【发布时间】:2013-08-18 16:46:26
【问题描述】:
print("Please enter your Weight")
weight = input(">")
print("Please enter your height")
height = input(">")
bmi = weight/height
if int(bmi) <= 18:
print("you are currently under weight")
elif int(bmi)>=24:
print("you are normal weight")
else:
print("you are over weight")
追溯
File "C:\Users\reazonsraj\Desktop\123.py", line 6, in <module>
bmi = weight/height
TypeError: unsupported operand type(s) for /: 'str' and 'str'
【问题讨论】:
-
您正在输入一个字符串,然后尝试将其与字符串分开,将您的输入转换为 int
-
使用
int:int(weight)/int(height) -
顺便说一句,这不是您计算 BMI 的方式。