i'm trying to make a calculator that can do 5 processes which are to add, subtract, multiply, divide and square root values that users input. all of that i've done, but when trying to make the values != float and int, the error comes for when the input values are float and int... i've tried value == str then error to come up, but even that doesnt work... anyone help me please?
e.g.
if value[0] != 'float' or value[0] != 'int' or value[1] != 'float' or value[1] != int':
return 'the input value is not correct
i've tried both the two in the above and it does not seem to work. as in the program is not able to read between a float, int and a string.
if i input
calculator('+', 3, 4)
the result says the error.....
the reason why i have the 'print type(value[0], [1]) is to make sure the types they are for the error that keeps on occuring. `
def calculator(sym, *t):
value = tuple(t)
n = len(value)
print type(value[0])
print type(value[1])
if value[0] != 'float' or value[0] != 'int' or value[1] != 'float' or value[1] != int':
return 'the input value is not correct.'
else:
if sym == '+':
if len(value) != 2:
return 'The input value is not correct.'
else:
return float(value[0] + value[1])
elif sym == '-':
if len(value) != 2:
return 'The input value is not correct.'
else:
return float(value[0] - value[1])
elif sym == '/':
if len(value) != 2:
return 'The input value is not correct.'
elif value[1] == 0:
return 'The input value is not correct.'
else:
return float(value[0] / value[1])
elif sym == '*':
if len(value) != 2:
return 'The input value is not correct.'
else:
return float(value[0] * value[1])
elif sym == 'sqrt':
if len(value) != 1:
return 'The input value is not correct.'
elif value[0] < 0:
return 'The input value is not correct.'
else:
return value[0] ** 0.5
else:
return 'The input value is not correct.'
`