score = float(input("Score: "))
if score >= 0 and score <= 1.0:
elif score >= 0.9:
print("A")
elif score >= 0.8:
print("B")
elif score >= 0.7:
print("C")
elif score >= 0.6:
print("D")
elif score < 0.6:
print("F")
else:
print("Bad Score")
尝试运行此简单代码,但输出给我一个语法错误,我无法识别
输出:
File C:\Python\Aprendizado 2 (PY for Everybody)\2.15.7.py", line 3
elif score >= 0.9:
^
SyntaxError: invalid syntax
一旦进入
if
块,您需要在其中定义另一个if
条件,然后才能访问elif
,否则它将出错,因为您试图引用不在块范围内的if
相关问题 更多 >
编程相关推荐