Write a Python program to add two objects if both objects are an integer type


Introduction

Write a Python program to add two objects if both objects are an integer type. I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. def add_numbers(x, y):
  2. if not (isinstance(x, int) and isinstance(y, int)):
  3. raise TypeError("Inputs must be integers")
  4. return x + y
  5.  
  6. print(add_numbers(30, 20))
  7.  

Result

python language techstudy.org

     





Related Topics




Popular Posts