【发布时间】:2017-02-20 11:21:59
【问题描述】:
已经搜索了一个 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)
【问题讨论】:
-
查看
while循环 -
谢谢 WhatsThepoint 我现在就去看看!
-
我不清楚你到底想做什么,但首先我认为如果你以更一般的方式搜索你的问题会更容易;你想做的类似于
while循环here。之后,您需要查看调用函数和传递参数。print (thirdpage)可能看起来像print page3(ch1),而def page3():看起来更像def page3(usr_input): print "\n %s" % usr_input。但正如我所说,我并不完全清楚。 -
谢谢罗根乔什!我正在使用实际选择你自己的冒险平装本,并试图创建一个运行就像你正在阅读这本书的程序作为示例“你在第 5 页,你选择去第 10 页还是第 12 页?”等等。 for while 循环看起来就像我需要的一样谢谢!
标签: python conditional user-input