在你问之前,我确实看过其他答案和问题,他们似乎都是一样的,是的,我确实添加了但仍然没有。好的,所以我有一个带菜单的程序,在菜单选项中它会在“:”冒号处出现语法错误,请帮助我尝试了所有内容。 这是代码:
def main():
print("Hello and Welcome to the 'Say When' program")
print("1:Class\n2:Priamry\n3:Secondary\n4:FirstGag\n5:SecondGag")
menu = (input("What would you like to search?: ")
if menu == '1':
print("You chose Class")
list = ['Assault', 'Engineer', 'Support', 'Recon']
from random import choice
print(choice(list))
elif menu == '2'
print("nice")
错误= 语法错误然后突出显示红色的“:”。
答案 0 :(得分:1)
您错过了input
函数的右括号,您完全不需要它。
menu = input("What would you like to search?: ")
完整的固定代码:
def main():
print("Hello and Welcome to the 'Say When' program")
print("1:Class\n2:Priamry\n3:Secondary\n4:FirstGag\n5:SecondGag")
menu = input("What would you like to search?: ")
if menu == '1':
print("You chose Class")
list = ['Assault', 'Engineer', 'Support', 'Recon']
from random import choice
print(choice(list))
elif menu == '2':
print("nice")
答案 1 :(得分:1)
input()
在开头有一个不必要的禁忌。if
语句错误缩进。elif
没有:
更正代码
from random import choice
def main():
print("Hello and Welcome to the 'Say When' program")
print("1:Class\n2:Priamry\n3:Secondary\n4:FirstGag\n5:SecondGag")
menu = input("What would you like to search?: ")
if menu == '1':
print("You chose Class")
list = ['Assault', 'Engineer', 'Support', 'Recon']
print(choice(list))
elif menu == '2':
print("nice")