Change the function z = float(x+y)
to z = float(x)+ float(y)
At this point we assume we are just adding numbers together.
Let's make sure we're always working with floats. Convert your arguments to floats before you add them together. You can do this with the float() function.
Ok let's make sure no matter what comes in it's converted to a float
def add(x, y):
z = float(x)+ float(y)
print "The required Sum is: {}".format(z)
return z
add (5, 8)
But what if a & b are strings ?? Need to take care of that.
def add(x, y)
try:
a = float(x)
b = float(y)
except ValueError:
return None
else:
return True
By the way, No need to check the datatype in python, making it much simpler
def addSum(x,y):
return x+y
addSum(2.2, 5.6)
7.8
addSum(float(2), float(5))
7.0
addSum(2, 5)
7
addSum("Hello ", "World!!")
'Hello World'