这是代码:
Weight = float(input("Enter weight in Kilograms: "))
Height = float(input("Enter height in meters: "))
BMI = (Weight / (Height**2))
print ("%.2f" %BMI)
if BMI < 18.5:
print ("You are under weight")
elif BMI >= 18.5 and < 25.0:
print ("You weight is normal")
elif BMI >= 25.0 and < 30.0:
print ("You are overweight")
elif BMI >= 30.0:
print ("You are overweight")
在线获取无效语法
elif BMI> = 18.5且
最佳答案
>
,<
和其他都是二进制运算符。它在每一侧寻找一个操作数,当它在左侧找到一个关键字时,and < 25.0
会抛出一个SyntaxError
。
正常的方法是:
if BMI >= 18.5 and BMI < 25.0:
但是,存在不平等的捷径:
if BMT < 18.5:
# underweight
elif 18.5 <= BMI < 25.0:
# normal
elif 25.0 <= BMI < 30:
# overweight
elif 30 <= BMI:
# super overweight
关于python - 以下代码第7行中的Python 3.3:无效语法错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28574935/