嗨,我正在使用Python进行编程,并且在主函数中不断收到语法错误。在if语句后, “if points> = 9 < = 51:”Python告诉我冒号是语法错误。我写了类似于这个任务的Python代码,我似乎无法找到问题。谁能帮我?if语句中的Python语法错误
非常感谢。
def variable(points):
if points >= 9 <= 51:
print('Valid Points')
else:
print('Invalid Points')
return points
def main():
points = int(input('Enter how many points you scored: ')
if points >= 9 <= 51:
points = variable(points)
else:
points = variable(points)
main()
'if points> = 9 <= 51:'不是一个赋值,它是一个比较。这行代码是正确的,但它可能不是你想要的。例如,如果分数是“100”,它将评估为“真”,因为“9”总是小于“51”。你可能想'如果9 <=分<= 51:'。 – 2012-02-28 00:45:56
请检查关于'input()'和'raw_input()'之间差异的文档。我非常怀疑你想让用户输入任意的python表达式! – ThiefMaster 2012-03-13 14:51:06