我正在通過「學習python hardway」。我很抱歉,如果這是重複的,但我真的不知道我做錯了什麼。當我輸入小於50的數字時,它告訴我再次嘗試,並在第二次調用另一個函數中的字符串。如果我在第二個條目中輸入大於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()
你永遠不會改變'too_much',所以第一個'if'永遠不會成功。 – Barmar
在第二個函數中,你永遠不會改變'wrong_ans',所以第一個'if'永遠不會成功。 – Barmar
這兩個變量有什麼意義? – Barmar