【发布时间】:2014-11-17 19:22:44
【问题描述】:
python 新手,从事文本冒险,测试函数的使用。
def cell1():
loop = 1
while loop == 1:
print("ONE")
cave1 = input()
if cave1 == ("end?"):
print("\nthis should end program")
loop = 0
break
elif cave1 == ("TWO"):
global testvar
testvar = 1
option1()
else:
print("INVALID")
def option1():
print("TWO")
loop = 1
while loop == 1:
print("test1 definition")
print (testvar)
test1 = input()
if test1 == ("ONE"):
print("you pick up the cheese")
loop = 0
cell1()
elif test1 == ("THREE"):
option2()
else:
print("INVALID")
def option2():
print("THREE")
loop = 1
while loop == 1:
print("This is option 3")
test2 = input()
if test2 == ("ONE"):
print("testering2")
cell1()
elif test2 == ("TWO"):
global testvar
testvar = 2014
option1()
else:
print("INVALID")
run = True
while run == (True):
print ("testing 123")
cell1()
print("restart about to activate")
cont = input("Restart? ")
if (cont) != "yes":
break
这个程序应该允许您在选项(房间是什么)之间切换,最终在 cell1 中,该程序应该是可结束的。
如果程序运行并且“结束?”输入为第一个输入,程序进入底部的继续位,但是,如果您在“房间”之间移动,然后返回单元格 1,输入“结束?”将调用选项 2。
我看了一圈还是觉得莫名其妙,我是不是搞错了什么?
感谢您的帮助,谢谢。
【问题讨论】:
-
提示:如果cell1调用option1,option1调用cell1,然后cell1结束,option1结束,第一个cell1调用仍会运行。