import time
def planeFun ():
print("The plane has spiked your intrest")
print(" s ")
skully=input("You ran a couple feet away, are you going to go look back in?\n")
if skully in ["Yes", "yes", " yes", " Yes", "y", "Y", "ya"]:
print("You decide to go and check back in, make sure what you saw is real!")
goin=input("should you investigate the plane more, or run away?\n")
return goin
planeFun()
result= planeFun()
if result in ["run", "Run", " run", " Run", "run away", "Run away", " run away", " Run away"]:
print("You decide to leave, something weird is going on, and you're not sticking around to find out")
我在这个程序中做错了什么?我试图解决它,但不能。每当输入'run'时,程序重新运行该功能,我无法弄清楚原因。
每当输入'run'时,程序重新运行该功能,我无法弄清楚原因。
这是由于planeFun
函数被调用两次:
planeFun() # <-- 1
result= planeFun() # <-- 2
除此之外,我还会推荐@ Jean-FrançoisFabre在评论中提到的内容。删除尾随和前导空格并使输入不区分大小写可以更容易检查某些结果:
def planeFun ():
print("The plane has spiked your intrest")
print(" s ")
skully=input("You ran a couple feet away, are you going to go look back in?\n").lower().strip()
这样你只需要检查小写文本,你可以删除大写重复检查。
倒数第二行,您键入:
`if reslut in ...`
尝试结果。
您应该填写“else”语句进行调试,意味着如果输入结果与输入不一致则打印