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.

def add_numbers(x, y):
    if not (isinstance(x, int) and isinstance(y, int)):
         raise TypeError("Inputs must be integers")
    return x + y
 
print(add_numbers(30, 20))

Result

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

Leave a Comment