2016-04-09 7 views
0

私はこのサイトを初めて利用しています。これは私の最初の投稿です。私は必要なものを入力するだけで答えを見つけることができますが、このために質問の語り方はわかりません。まだそれを修正しようとしている、約1時間今されているが、何が間違っているか分からない。Python If文で何も印刷されない

私のコードは以下の通りです。実行すると、自分の持つ機能(npcとstory)と正しいprint文が印刷され、ループの無限ループ何もせず、if文(印刷物 "STORYSTORYSTORY")があることに気付かないようです。私は、ループ内で実行されているゲーム全体を持って

while True: 
    print "\n You wake up in a small room, the lights are dim and the only thing you can see is a table with a few gold pieces and a glass of water." 
    input1 = raw_input ("What do you do?").lower() 
    if input1 == "take gold": 
     print "\n You take the gold and it's added to your inventory" 
     time.sleep(3) 
     npc("jenkins_gold") 
     story("part1") 
     loop == 2 
     break 
    if input1 == "drink water": 
     print "\n You reach for the water, and gulp it down." 
     time.sleep(3) 
     npc("jenkins_water") 
     story("part1") 
     loop == 2 
     break 

if loop == 2: 
    print "\n Story" 
    print "\n STORYSTORYSTORY" 

while True: 
    y = 1 
    x = y 
    time.sleep(1) 

は、ここに私のコードです。一番下にwhileループがあります。その場合は、何か関係があります。私のコードから他のものが必要な場合は、私に連絡してください。数分以内に返答してください。あなたの最初のwhileの文では、あなたに

+0

最後のループは何をする予定ですか? – Leva7

+1

あなたの質問は何か不明です。あなたが得る出力と期待する出力を投稿してください。 – jpo38

+0

ああ、私はこれらのコメントがここにあったことを気付かずに、見たことがありませんでした。私の質問には答えられました。他の人にとっては無駄な質問です。削除したり、解決するタイトルを変更したり、回答を受け入れたりできますか? –

答えて

1

ありがとう:loop == 2Trueに評価(あなたが==を使用するので、それは、ブール式だ)と他には何もしません、あなたは2loopに影響を与えるようにしたいので、あなたは(それがされるloop = 2を行う必要がありますあなたが=を使用するため、割り当て)。

while True: 
    print "\n You wake up in a small room, the lights are dim and the only thing you can see is a table with a few gold pieces and a glass of water." 
    input1 = raw_input ("What do you do?").lower() 
    if input1 == "take gold": 
     print "\n You take the gold and it's added to your inventory" 
     time.sleep(3) 
     npc("jenkins_gold") 
     story("part1") 
     loop = 2 
     break 
    if input1 == "drink water": 
     print "\n You reach for the water, and gulp it down." 
     time.sleep(3) 
     npc("jenkins_water") 
     story("part1") 
     loop = 2 
     break 
1

あなたは等価演算子==経由loopに2を代入しようとしています。代わりに代入演算子=を次のように割り当てます。

loop = 2 
関連する問題