2016-09-25 13 views
-1
def magic_n(guess2): #Function, have someone guess if number is 7, max 5 tries 
magicn2 == 7 
tries = 0 
while (tries < 5) and (guess2 != magicn2): 
if guess < 7 : 
    tries = tries + 1 
    print("Too Low") 
    guess2 = int(input("Give me another number since the last one was too high : ")) 
    elif guess > 7: 
    tries = tries + 1 
    print("Too high") 
    guess2 = int(input("Give me another number since the l ast one was too low : ") 
    else : 
    print("Good job you got it") 

guess2 = INT(入力( "私に数をしてください与える:") プリント(magic_n(guess2)ELIF、ELSE構文エラーのpython 3.2.1

謝罪を求め、この方法ではない場合には右、スタックオーバーフロー

+0

インデントが正しくありません。私はそれだと思います... –

+0

http://stackoverflow.com/questions/7025443/else-elif-statements-not-working-in-python –

+0

インデントはPythonでは非常に重要です。あなたは完全に間違っています。質問があなたのコードと正確に一致するように、最初に修正してください。また、コードブロック全体にインデントを追加することをお勧めします。これは、SOがコードであることを検出する方法であるためです。提出する前に確認できるプレビューがあります。 – zvone

答えて

1

を使用して、最初の時間は、インデントは適切ではない、とあなたは「他」の前に1つのより多くの括弧が必要

だから、次のようになります。

def magic_n(guess2): 
    magicn = 7 
    tries = 0 
    while (tries < 5) and (guess2 != magicn): 
     if guess2 < 7: 
      tries += 1 
      print("Too Low") 
      guess2 = int(input("Give me another number since the last one was too high : ")) 
     elif guess2 > 7: 
      tries += 1 
      print("Too high") 
      guess2 = int(input("Give me another number since the l ast one was too low : ")) 
     else: 
      print("Good job you got it") 
1

はい字下げ....

あなたはPythonを使用しています...あなたは今後このようなエラーを避けることができるので、PYCHARMを見てみることをお勧めします。私はそれをたくさん使用し、それはあなたのための自動フォーマット。

https://www.jetbrains.com/pycharm/

0

ライン12:コードスニペットは、私のブロック開始と場所、それはそう を終了がないかを理解する必要があるので、

guess2 = int(input("Give me another number since the l ast one was too low : ")) //bracket missing 

インデントがpython.thereに適切でなければなりませんが、Pythonで}ではありません

if condition: 
    ........ 
    ........ 
elif condition : 
    ........ 
    ........ 
else : 
    ........