如果返回错误答案(python)
我正在努力学习“艰苦学习python”。如果这是重复的,我很抱歉,但我真的不知道我做错了什么。当我输入小于50的值时,它告诉我再试一次,第二次调用另一个函数中的字符串。如果我在第二个条目中输入大于50的值,它将调用另一个函数中的另一个字符串。它将从green_dragon()调用并打印“两条龙都会活生生地烹饪你,吃掉你。”感谢你提供的任何见解。我很抱歉这么简单,哈哈。我不得不做我自己的“游戏”,我还没有那么有创意,哈哈如果返回错误答案(python),python,Python,我正在努力学习“艰苦学习python”。如果这是重复的,我很抱歉,但我真的不知道我做错了什么。当我输入小于50的值时,它告诉我再试一次,第二次调用另一个函数中的字符串。如果我在第二个条目中输入大于50的值,它将调用另一个函数中的另一个字符串。它将从green_dragon()调用并打印“两条龙都会活生生地烹饪你,吃掉你。”感谢你提供的任何见解。我很抱歉这么简单,哈哈。我不得不做我自己的“游戏”,我还没有那么有创意,哈哈 def gold_room(): print "You have e
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()
def gold_room():
打印“您进入了一个装满黄金的大房间。”
打印“你打算试着拿走多少块金子?”
选择=原始输入(“>”)
多少=整数(选择)
太多=错误
尽管如此:
如果有多少是50而不是太多:
打印“你这个贪婪的MFKR!"
打印“被你的贪婪激怒了,”
打印“龙咆哮,吓唬你减少服用。”
其他:
打印“再试一次!"
还多少钱
def green_dragon():
打印“你接近绿龙。”
打印“它小心地看着你。”
打印“你是做什么的?”
错误的
尽管如此:
选择=原始输入(“>”)
如果选择==“对着龙吼”并且回答错误:
死亡(“青龙用它的火焰气息把你烧成灰烬!”)
elif choice==“缓慢接近”且没有错误:
打印“它向你展示了它的锁环。”
elif选项==“取下衣领”且无误:
打印“龙带你进入一个新房间,感谢你。”
黄金屋
其他:
打印“两条龙都会活生生地煮你,吃掉你。”
退出()
你永远不会改变太多,所以第一个if
永远不会成功。而在第二个函数中,你永远不会改变错误的答案,所以第一个if
永远不会成功。这两个变量的意义是什么?对不起,改变“太多”?我想我必须将其设置为False和“while True”“将继续循环,直到输入小于或等于50的内容。我正试图让它继续请求输入,直到满足每个if的条件。我将其更改为True,它仍然执行相同的操作,但是现在没有打印出来的字符串了。我正在尝试制作我自己的文本游戏,作为这几节课练习的一部分,但它在一次跑完之后就停止了。我试图让它不断要求输入,直到它小于或等于50@MikeH如果用户输入大于50,它应该怎么做?再次征求意见?如果小于50,它应该做什么?你的编辑修复了它。是的,我希望它继续请求重试,直到输入小于或等于50。我认为,我的布尔设置错误,循环中没有choice=raw\u input(“>”)和choice=int(choice)是它可能一直调用另一个函数的原因。
too_much = False
if <= 50 and too_much
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."