TypeError: Unsupported Operand Type(s) For /: 'str' And 'float'
I am using Python 2 but I'm getting an error: TypeError: unsupported operand type(s) for /: 'str' and 'float' when the script runs to the last line. I don't understand which var
Solution 1:
from sys import argv
script, age, height=argv
print 'you\'re %r old'%age
weight=input('and i need your weight to calculate BMI, can you tell me:')
print 'your BMI is %r'%(weight/((float(height)/100)**2))
i found the solution, it's because a formula after % must be in ()
Solution 2:
weight = float(weight)
height = float(height)
age = int(age)
You forgot to convert the input from string to numeric. To diagnose:
print weight, type(weight)
print height, type(height)
print age, type(age)
...
Post a Comment for "TypeError: Unsupported Operand Type(s) For /: 'str' And 'float'"