Reputation: 47
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 variable is still a string type.
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)
Upvotes: 1
Views: 8049
Reputation: 47
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 ()
Upvotes: 3
Reputation: 77910
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)
...
Upvotes: 1