我正在使用Python 2,但我收到了错误:
TypeError: unsupported operand type(s) for /: 'str' and 'float'
当脚本运行到最后一行时。我不明白哪个变量仍然是字符串类型。
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)
答案 0 :(得分:2)
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))
我找到了解决方案,因为%之后的公式必须在()
中答案 1 :(得分:0)
weight = float(weight)
height = float(height)
age = int(age)
您忘记将输入从字符串转换为数字。诊断:
print weight, type(weight)
print height, type(height)
print age, type(age)
...