Python: Add two objects if both objects are an integer type
Python Basic: Exercise-36 with Solution
Write a Python program to add two objects if both objects are an integer type.
Sample Solution:-
def add_numbers(a, b):
if not (isinstance(a, int) and isinstance(b, int)):
raise TypeError("Inputs must be integers")
return a + b
print(add_numbers(10, 20))
print(add_numbers(1234, 8765))
========= RESTART: F:/Python_APSC/py-ex-basic-36.py ===========
30
9999
>>>
沒有留言:
張貼留言