Python3.3:下面代码的第7行出现无效语法错误

2024-09-28 22:03:38 发布

您现在位置:Python中文网/ 问答频道 /正文

代码如下:

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:


Tags: and代码inyouinputfloatareprint
1条回答
网友
1楼 · 发布于 2024-09-28 22:03:38

><,其余都是二进制运算符。它在每边寻找一个操作数,当它在左边找到一个关键字时and < 25.0抛出一个SyntaxError。在

通常的方法是:

if BMI >= 18.5 and BMI < 25.0:

但不平等有捷径:

^{pr2}$

相关问题 更多 >