繁体   English   中英

以下代码第7行中的Python 3.3:无效语法错误

[英]Python 3.3: Invalid Syntax error in line 7 of the below code

这是代码:

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和<25.0行处获取无效语法:

><和其余都是二进制运算符。 它在两侧寻找一个操作数,当它在左侧找到一个关键字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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM