2016-08-06 9 views
-1

私は、あなたが気にしているファーム動物をコンピュータが知っているゲームを構築しています。彼はあなたの家畜を推測するためにあなたに質問します。しかし、私はエラーが発生し、私はそれを修正する方法を知らない。"elif"構文エラー

マイコード:

qs_one = raw_input("Do your animal walk on two legs? answar 'yes' or 'no'") 
if qs_one == "yes": 
    qs_two = raw_input("Do your animal have a white skin? answar 'yes' or 'no'") 
    if qs_two == "yes": 
     print "Your animal is a goose!" 
    elif qs_two == "no": 
     print "Your animal is a chicken!" 
    else: 
     print "Error, try again." 
elif qs_one == "no": 
    qs_two = raw_input("Do your animal have horns? answar 'yes' or 'no'") 
    if qs_two == "yes": 
     qs_tree = raw_input("Do your animal have stains? answar 'yes' or 'no'") 
     if qs_tree == "yes": 
      print "Your animal is a cow!" 
     elif qs_tree == "no": 
      qs_four = raw_input("Do your animal have goatee? answar 'yes' or 'no'") 
      if qs_four == "yes": 
       print "Your animal is a goat!" 
      elif qs_four == "no": 
       print "Your animal is a bull!" 
      else: 
       print "Error, try again." 
     else: 
      print "Error, try again." 
    elif qs_two == "no": 
     qs_tree = raw_input("Do your animal have a pink skin? answar 'yes' or 'no'") 
     if qs_tree == "yes": 
      print "Your animal is a pig!" 
     elif: # <- ERROR HERE 
      qs_four = raw_input("Can you ride your animal? answar 'yes' or 'no'") 
      if qs_four == "yes": 
       print "Your animal is a horse!" 
      elif qs_four == "no": 
       qs_five = raw_input("Does your animal have big ears? answar 'yes' or 'no'") 
       if qs_five == "yes": 
        "Your animal is a rabbit!" 
       elif qs_five == "no": 
        "Your animal is a sheep!" 
       else: 
        print "Error, try again." 
      else: 
       print "Error, try again." 
     else: 
      print "Error, try again." 
    else: 
     print "Error, try again." 
else: 
    print "Error, try again." 

がエラー:

Traceback (most recent call last): 
File "python", line 30 
elif: 
    ^
SyntaxError: invalid syntax`` 
+1

あなたのインデントはすべての場所にあります。問題を再現できるように、あなたの質問に*正しい*字下げがあることを確認してください。 –

+1

あなたが探しているコマンドは、elifが条件を必要とするelse ifステートメントであるため、それ以外のものだと思います。 – thesonyman101

答えて

4

あなたはすなわち

elif condition_is_true: 
    *do something* 

elifに条件を持っている必要があります私はあなたが何をしたいのかを考えることですelif qs_tree=='no':を使用してください。 「はい」の場合は豚、「いいえ」の場合はそれ以外の場合は「他のすべての回答は「エラー、再試行」メッセージを送信する必要があります。

+0

'qs_tree ==" yes ":' 'yes ''または '' no' 'の質問には、' 'else:'が必要です。 – martineau

+0

@martineau私は彼がはい/いいえ/他の質問をしたいと思う、唯一の2つの有効な答えがはいといいえであるので。それ以外のものはすべて「else」によって捕らえられなければならない。 – pathoren