2016-09-08 22 views
-1

私がPython 2.7からPython 3.5に行ったとき、私はELIF文に問題があり始めました。 「...なぜELIFが無効です構文エラーですか?

doesnのを私はのelif文を入力したときにそれがエラーを示しており、この1

this is what jumps up as error solution

PyCharmを使用していますが、私はそれを押したときにこの問題が発生したが、コードはまだ動作しません。私はこの写真を投稿させていただきます、それはコメントになります

何かの理由で私はポストコードを書き留めていませんので、もしあなたが彼を必要としている場合はコメントになります。私はどこにでも助けを見つけることができませんし、よくそれは本当に面倒です...

+0

裸の 'elif'文の前に' if'を付ける必要はありません。それに加えて、 'if'は等号演算子' == 'を使い、' = 'で代入しないでください。 –

答えて

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") 
+0

ohhh、ありがとう、ありがとう!これは私をたくさん助けました! – Raptr3x

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) 
関連する問題