-1

Have searched for a python choose your own adventure game but the closest I have found is the text based game 'Droids' which i have used some code from to create the conditional below that prints pages of a book depending on user input. My question is how do I create a conditional that will prompt after every page is displayed to the user and return the correct page and then display a new prompt to continue the story.

#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)
  • look in to `while` loops – WhatsThePoint Feb 20 '17 at 11:24
  • Thanks WhatsThepoint ill check them out now! – Jordan Selby Feb 20 '17 at 11:29
  • I'm not clear on what exactly you're trying to do but firstly I think it would be easier if you search for your issue in more general ways; what you want to do is similar to a `while` loop [here](http://stackoverflow.com/questions/20337489/python-how-to-keep-repeating-a-program-until-a-specific-input-is-obtained). After that, you need to look at calling functions and passing arguments. `print (thirdpage)` is likely meant to look something like `print page3(ch1)` with `def page3():` looking more like `def page3(usr_input): print "\n %s" % usr_input`. But as I said, I'm not completely clear. – roganjosh Feb 20 '17 at 11:30
  • Thanks roganjosh! I am using an actual choose your own adventure paperback and am trying to create a program that runs like you are reading the book as an example 'you are on pg 5 do you choose to go to pg 10 or 12?' and so on. The for while loops look exactly like what I need thankyou! – Jordan Selby Feb 20 '17 at 11:40

1 Answers1

0

A looping while function helped me out with this courtesy of 'roganjosh, WhatsThePoint'

while True:
    inp = raw_input(">>> ").lower()