2016-08-06 7 views
-1

このPythonファイルの多くのエラーは修正されましたが、動作しない最後のものが1つあります。はいまたはいいえが入力されていない場合、もう一度質問をするためにループするためにelse文が必要です。あなたはおそらく私が行っていたことをコードで見ることができますが、私はおそらく正しい軌道にもないでしょう。誰かがこの最後のことを私に助けてくれる?Python:Loop Prompt Back around

#These are my variables which are just strings entered by the user. 
friend = raw_input("Who is your friend? ") 
my_name = raw_input("Enter Your Name: ") 
game_system = raw_input("What's your favorite game system? ") 
game_name = raw_input("What's your favorite game for that system? ") 
game_status = raw_input("Do you have the game? (Yes or No) ") 
game_store = raw_input("What is your favorite game store? ") 
game_price = raw_input("What's the price of the game today? Enter a whole number. ") 

#This is what is printed after all the prompts. There is no condition for this print. 
print "I went outside today and my friend " + friend + " was outside waiting for me. He said \"" + my_name + ", did you get the new " + game_system + " game yet? You were getting " + game_name + " today, right?\"" 

#If the condition on the Yes or No question is yes, then this code runs. 
if game_status == "YES": 
    print "\"You know I got it, man!\" I said. \"Awesome! Let's play it,\" he said. \"I heard " + game_name + " is supposed to be amazing!\" We went back inside and took turns playing until " + friend + " had to go home. Today was a fun day." 

#If the condition is No, then this code runs. 
elif game_status == "No": 
    print "\"Well let's go get it today and we can come back here and play it!\" We went down to " + game_store + " and baught " + game_name + " for $" + str(game_price) + " and we went back to my house to take turns playing until " + friend + " went home. Today was a good day. (Now try again with the No option!)" 

#If the condition meets neither Yes or No, then this code runs, sending the user back to the same question again. This repeats until a condition is met. 
else: 
    raw_input("That answer didn't work. Try again? Do you have the game? (Yes or No) ") 
+0

行くべき、同様

if game_status == "YES": 

に行く必要がありますそこに行こう。 – user2357112

+0

これは本当に具体的ではありません。そこには3つのコロンがあります。 –

答えて

2

この:

if game_status: "YES" 

あなたがif文を作る方法ではありません。文法が

if some_variable: some_value 

のように扱い、変数にその値がある場合は、if文がトリガーされます。実際には、構文は

if some_expression: 

となり、式が真と見なされると評価された場合、if文がトリガされます。あなたはif文がgame_status"YES"に等しいでトリガしたい場合は、式はgame_status == "YES"する必要があり、そうifラインはelifラインはコロンがない

elif game_status == "NO": 
+0

それは私が必要としていたものです!どうもありがとうございます!私はまだ学んでおり、これは大きな助けとなっていました。あなたはチェックマークがついています。 –

2

私はいつもの「if game_status:」の後にインデントされ、条件付き...

if game_status == "YES": 
    print "\"You know I got it, man!\" I said. \"Awesome! Let's play it,\" he said. \"I heard " + game_name + " is supposed to be amazing!\" We went back inside and took turns playing until " + friend + " had to go home. Today was a fun day." 

何も後に新しい行を破るあなたに励ますの実行を取得します。そしてそれはより良く読む。

編集 ::あなたはすべての文字列のための単一引用符を使用する場合、あなたは二重引用符をエスケープする必要はありません...

print '"You know I got it, man!" I said. "Awesome! Let\'s play it," he said. "I heard ' + game_name + ' is supposed to be amazing!" We went back inside and took turns playing until ' + friend + ' had to go home. Today was a fun day.' 

それは好みの問題だ...しかし、あまり見えるかもしれません混乱した。

+0

私は分かりませんでした。私はまだPythonには新しかったので、私は最も長い間私を悩ませていました。助けてくれてありがとう!今私はこれらの他のエラーを修正する必要があります。 –

+1

これによりエラーは消えますが、修正されません。違ったことをしているだけです。 – user2357112

+1

@ user2357112ありがとう!あなたはまったく正しい...編集修正を行った。 – user1269942