我正在通过"学习python the Farge"进行工作。如果这是重复的话,我深表歉意,但我真的不知道自己在做什么错。当我输入少于50的内容时,它告诉我再次尝试,第二次在另一个功能中调用字符串。如果我在第二个条目中输入大于50件的东西,它将在另一个功能中调用另一个字符串。它将从green_dragon()打来电话,并打印"两个龙都活着煮了你并吃掉你。"感谢您提供的任何见解。对于简单性,我深表歉意,大声笑。必须制作自己的"游戏,我还没有创造力,大声笑。
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 = False
if <= 50 and too_much
如果too_much
设置为false,为什么您期望IF表达式评估为true?它永远不会进入if
。
也将用户输入移入循环中。
编辑:
停止您的时循环:
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."