writing a python function Add_Values(a,b) (Refer RollNo_W10A_2.py)which takes either two integer or float or string input parameters and perform addition/concatenation if the type of both parameters is the same otherwise give an exception as shown in the example.
def Add_Values(a, b):
if type(a) == type(b):
return a+b
else:
return 'a and b have different data type'
print(Add_Values(1, 'str')) # a and b have different data type
print(Add_Values(1, 5)) # 6
print(Add_Values(2.3, 6)) # a and b have different data type
print(Add_Values('str1', 'str2')) # str1str2
Comments
Leave a comment