2017-02-24 9 views
0

私は "python the hardwayを学ぶ"の作業をしています。私はこれが重複している場合は謝罪しますが、本当に私が間違っていることを理解することはできません。私は50未満のものを入力すると、もう一度やり直すように指示し、2回目に別の関数で文字列を呼び出します。 2番目のエントリに50以上の同じものを入力すると、別の関数で別の文字列が呼び出されます。 green_dragon()から呼び出され、 "両方のドラゴンがあなたを生きていて、あなたを食べる"という印字をします。あなたが提供できるどんな洞察力もありがとうございます。私はシンプルさ、笑を謝罪します。私自身の「ゲームをしなければならなかったと私は笑、そのクリエイティブはまだいないよ。間違った答え(python)を返した場合

def gold_room(): 
    print "You have entered a large room filled with gold." 
    print "How many pieces of this gold are you going to try and take?" 
    choice = raw_input("> ") 
    how_much = int(choice) 
    too_much = False 
    while True: 
     if how_much <= 50 and too_much: 
      print "Nice! you're not too greedy!" 
      print "Enjoy the gold you lucky S.O.B!" 
      exit("Bye!") 

     elif how_much > 50 and not too_much: 
      print "You greedy MFKR!" 
      print "Angered by your greed," 
      print "the dragons roar and scare you into taking less." 

     else: 
      print "Try again!" 
     return how_much 

def green_dragon(): 
    print "You approach the green dragon." 
    print "It looks at you warily." 
    print "What do you do?" 
    wrong_ans = False 
    while True: 
     choice = raw_input("> ") 

     if choice == "yell at dragon" and wrong_ans: 
      dead("The Green Dragon incinerates you with it's fire breath!") 
     elif choice == "approach slowly" and not wrong_ans: 
      print "It shows you its chained collar." 
     elif choice == "remove collar"and not wrong_ans: 
      print "The dragon thanks you by showing you into a new room." 
      gold_room() 
     else: 
      print "Both dragons cook you alive and eat you." 
      exit() 
+0

あなたは 'too_much'を変更することはありません、最初の' if'が成功することはありませんので。 – Barmar

+0

2番目の関数では、 'wrong_ans'を決して変更しないので、最初の' if'は決して成功できません。 – Barmar

+0

これらの2つの変数のポイントは何ですか? – Barmar

答えて

1
too_much = False 

if <= 50 and too_much 

too_muchがFalseに設定されている場合は、なぜあなたは、if式がtrueに評価する期待していますか?それは決してifの内側に行くだけでなく、ループ内
移動ユーザー入力

EDIT:。。

は、あなたのwhileループを停止するには:

 too_much = True 
     while too_much: 
      choice = raw_input("> ") 
      how_much = int(choice) 
      if how_much <= 50: 
       print "Nice! you're not too greedy!" 
       print "Enjoy the gold you lucky S.O.B!" 
       too_much = False 
      else: 
       print "You greedy MFKR!" 
       print "Angered by your greed," 
       print "the dragons roar and scare you into taking less." 
+0

私はそれをTrueに変更しましたが、同じことを今でも行っています。 –

+0

私はこれらのレッスンでエクササイズの一環として自分のテキストゲームを作ろうとしています –

+0

1つの実行後に停止していませんでした。私はそれが50以下になるまで入力を求め続けようとしています –

関連する問題