旁注:这只是一个更大代码的一部分,它告诉你应该摄入多少克脂肪。但现在我被困在这里
try:
weight = float(input("""What is your weight (Kg)?
>>> """))
height = float(input("""What your height (m)?
>>> """))
except ValueError:
print("Incorrect input")
continue
bmi = weight / (height * height), 2
print(name + " your BMI is " + str(bmi))
bmi2 = float('.'.join(str(ele) for ele in bmi))
if bmi2 < 18.4:
print("You are under weight by BMI standards!")
elif bmi2 == 18.5 and bmi2 <= 24.9:
print("You are normal weight by BMI standards!")
elif bmi2 == 25 and bmi2 <= 29.9:
print("You are over weight by BMI standards!")
elif bmi2 == 30 and bmi2 <= 34.9:
print("You have obesity (class 1) by BMI standards!")
elif bmi2 == 35 and bmi2 <= 39.9:
print("You have obesity (class 2) by BMI standards!")
elif bmi2 > 40:
print("You have obesity (class 3) by BMI standards!")
您的代码有一些问题,让我们来看看:
continue
语句。您没有处于循环或switch
中李>name
的变量。我猜您是在提供的代码之外定义的,但是如果不是,您必须定义它李>tuple
。这可以追溯到第9行(编辑前的第10行),在那里您将其定义为weight / (height * height), 2
。移除, 2
李>bmi2
试图做什么,您只需在这些函数中使用bmi
,就可以正常工作李>==
运算符更改为>;=,以及and
到or
的and
语句李>相关问题 更多 >
编程相关推荐