嘿伙计我正在使用Python进行编程,并且我在main函数中不断出现语法错误。在if语句之后, “if points> = 9< = 51:”Python告诉我冒号是语法错误。我写了类似于这个任务的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()
答案 0 :(得分:3)
你的语法和缩进有点偏。尝试
>>> def variable(points):
... if 9<= points<= 51:
... print('Valid Points')
... else:
... print('Invalid Points')
...
...
>>> variable(34)
Valid Points
同样适用于你的def main():
,并且
points = int(input('Enter how many points you scored: ')
答案 1 :(得分:1)
除了不平等问题,您忘记了尾随)
:
points = int(input('Enter how many points you scored: ')
答案 2 :(得分:1)
缩进是错误的,并且缺少括号。
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()
答案 3 :(得分:0)
你忘了关闭一个人。
points = int(input('Enter how many points you scored: '))