我正在通过“学习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