Write a Python program to add two objects if both objects are integers.

Write a Python program to add two objects if both objects are integers.

1
2
3
4
5
6
7
8
def add_numbers(a, b):
   if not (isinstance(a, int) and isinstance(b, int)):
       return "Inputs must be integers!"
   return a + b
print(add_numbers(10, 20))
print(add_numbers(10, 20.23))
print(add_numbers('5', 6))
print(add_numbers('5', '6'))

Final output

Leave a Comment