当我从python 2.7到python 3.5时,我开始遇到ELIF语句问题。 我正在使用PyCharm,所以当我输入elif语句时,它会显示错误并显示1
this is what jumps up as error solution
当我按下它时会发生这种情况,但代码仍然不起作用......
不允许我发布这张照片,它会在评论中
无论如何,由于某种原因,我无法发布代码,所以如果你需要他就会在评论中提出帮助,如果可以的话请帮助我,因为这不是第一次发生,我无法在任何地方找到帮助而且很好#&# 39;真的很烦人......
答案 0 :(得分:1)
您的第一个错误是没有初始if
语句以及game = '1':
而不是game == '1':
。如果您查看我的代码,我已修复了这些错误并修复了缩进,因为它导致了一些错误
import os
print("\nWelcome, enter Your name please")
name = input("--> ")
def username(name): #NAME
while len(name) < 2:
print("There was an error")
name = input("\nPlease enter Your name again -->")
else:
print("Hello,", name)
username(name)
def menu(): #MENU
print("\nWelcome to the menu")
print("From here You can chose the game")
print("For now, we have only 3 game but there will be plenty more!")
print("Chose game by it's number ")
print("1 - Coin flip| 2 - Horse racing| 3 - Loto|")
menu()
game = int(input("--> "))
def choice(game): #CHOOSING GAME
while game > 3 or game < 1:
print("\nSomething went wrong, enter game you want again (only numbers 1, 2, 3!")
game = int(input("--> "))
if game == '1': #if statement first and two "=" signs
print("You chose Coin flip game")
os.system('python coinflip.py')
elif game == '2': #use tab to indent properly
print("You chose Horse racing game")
os.system('python horseracing.py')
elif game == '3': #keep indentations the same throughout
print("You chose Loto game")
os.system("python loto.py")
choice(game)
答案 1 :(得分:0)
您需要先输入“if”和“elif”。所以它应该是这样的:
def choice(game): #CHOOSING GAME
while game > 3 or game < 1:
print("\nSomething went wrong, enter game you want again (only numbers 1, 2, 3!")
game = int(input("--> "))
if game == '1': #bug here
print("You chose Coin flip game")
os.system('python coinflip.py')
elif game == '2': #and here
print("You chose Horse racing game")
os.system('python horseracing.py')
elif game == '3': #and here
print("You chose Loto game")
os.system("python loto.py")