2016-09-08 2 views
-1

파이썬 2.7에서 파이썬 3.5로 갔을 때 나는 ELIF 문장에 문제가 생기기 시작했다. 내가 PyCharm을 사용하고 내가 ELIF 문을 입력 할 때 그래서 오류를 표시하고이 1ELIF 구문 오류가 잘못 표시되는 이유는 무엇입니까?

this is what jumps up as error solution

내가 그것을 누를 때이 코드를 아직하지 않습니다 작품 ...

아무튼 '그러나 발생 t이 사진을 게시하게 해주세요. 코멘트에 있습니다.

어쨌든, 나는 어떤 이유로 든 포스트 코드를 포기할 수 없으므로, 만약 당신이 그를 필요로하고, 이것이 가능하지 않다면 도움을주십시오. 어디서나 도움을 찾을 수 없으며 실제로 성가시다 ...

+0

당신이 그들이'if'가 선행 될 필요가 맨'elif' 문을 가질 수 없습니다 원인이되었을 들여 쓰기를 고정. 그 외에도,'if'는'='를 사용하고'='를 사용하여 대입 연산자를 사용하지 않아야합니다. –

답변

0

먼저 "if"와 "elif"를 입력해야합니다. 그래서 그런 일해야한다 : 첫 번째 오류가 초기 if 문을 가진뿐만 아니라 game == '1': 대신 game = '1':를 가지고 있지 않습니다

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

오, 알겠습니다, 정말 고마워요! 이것은 나를 많이 도왔습니다! – Raptr3x

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) 
관련 문제