2017-02-20 28 views
0

已经搜索了一个python选择你自己的冒险游戏,但最近我发现的是基于文本的游戏'Droids',我使用了一些代码来创建下面的条件打印页面取决于用户的输入。我的问题是如何创建一个条件,在向用户显示每个页面之后提示,并返回正确的页面,然后显示新的提示以继续故事。用户提示选择你自己的冒险游戏

#Defines the first page that is displayed 
def page0(): 
    print "\n %s" % firstpage 

def page3(): 
    print "\n %s" % thirdpage 

def page10(): 
    print "\n %s" % tenthpage 

#prints page 0 
print page0() 

#Choice 1 returns page 3 or 10 
ch1 = str(input("Type 3 or 10: ")) 


if ch1 in ['3']: 
    print (thirdpage) 

elif ch1 in ['10']: 
    print (tenthpage) 
+0

来看一下,'while'循环 – WhatsThePoint

+0

感谢WhatsThepoint病检查出来吧! –

+0

我不清楚你究竟在做什么,但首先我认为如果你用更一般的方式搜索你的问题会更容易;你想要做的是类似于'while'循环[这里](http://stackoverflow.com/questions/20337489/python-how-to-keep-repeating-a-program-until-a-specific-input -is得到的)。之后,您需要查看调用函数和传递参数。 'print page3(ch1)''看起来更像是'def page3(usr_input):print'\ n%s“%usr_input'。但正如我所说,我不完全清楚。 – roganjosh

回答

0

一个循环while功能帮了我这个礼貌的 'roganjosh,WhatsThePoint'

while True: 
    inp = raw_input(">>> ").lower() 
相关问题