0

I'm very new to using Python (ver 3.4) and decided to jump right in and create a very simple, somewhat linear, choose your own adventure text game. I'm having trouble with it though. Here is a sample of the code:

def intro():
    print('''****intro text here****''')
    print("Do you want to: 1. option1 2. option2")

    choice = input()
    if choice == 1:
        choice1()
    elif choice == 2:
        choice2()
    else:
        intro()

I can't seem to get this function to run without making an infinite loop. If I add:

intro()

under it then no matter the input it just loops back to the beginning and does the whole intro over again. Any help is appreciated.

  • 6
    That's because `input()` returns a string, not an integer. The `== 1` and `== 2` tests are always going to be false. – Martijn Pieters Sep 02 '16 at 18:10
  • 2
    You also want to read [Asking the user for input until they give a valid response](http://stackoverflow.com/q/23294658) and avoid using recursion. – Martijn Pieters Sep 02 '16 at 18:10
  • Definitely avoid recursion unless you have a strong need for it. You probably want your 'else' clause to raise an error instead. – Sohier Dane Sep 02 '16 at 18:12

0 Answers0