mercredi 29 juillet 2020

Python function (ifs and inputs) stops partway through, no error

I'm using a series of inputs and if statements to create a text game/ choose your own adventure where input decides what happens next within a function. I was testing part of a function, and there should be a total of four strings that print with an input prompt, but after the first two it just moves onto the cell after the function. No error message. I'm using Jupyter Notebook with the latest version of Python. Any help appreciated in making the full function run. (Please ignore the goofy text, sorry for errors this is my first question)

start = input('Welcome to Witness Protection, enter HELP if you need help')
def helper():
if start == 'HELP':
    answer= input('Woah. As you are walking to the FBI office, you see a glistening penny on the floor. Something about it looks strange. What do you do? Enter PICK to pick it up or WALK to keep walking')
    if answer == 'PICK':
        answer= input('You reach down and grasp the penny, and try to pull it. It doesn’t move. Enter TRY to try again or WALK AWAY to walk away')
    elif answer == 'WALK':
        print('You enter the building and make your way to the office of your agent, and sit down to wait for them.')
        if answer == 'TRY':
            answer= input('The penny clicks out of place and slides along a track between the paving slabs. One of the slabs slides open. Enter IN to climb in or PUT to put the penny back where it was')
        elif answer == 'WALK AWAY':
            print('You keep walking until you reach the FBI office. You make your way to the office of your agent, and sit down to wait for them.')
            if answer == 'IN':
                answer = input('A few metres down, you hit the floor, and see the opening above you close up. You find yourself in an ice cavern, surrounded by the bodies of slain ice dwarfs. Enter ON to walk on or BACK to back')
            elif answer == 'PUT':
                print('You move the penny back to where it was, and the slab slides back into place. You continue your walk towards the FBI offices, and wait for your agent in front of their desk')
                if answer == 'ON':
                    answer = input('You enter the realm of the evil wizard. He tells you he is thinking of giving up evil and asks you if you would like to join him in taking over the world and establishing a utopia. Enter YES for  \'Of course I will join you, let’s do this!\' Enter THINK for \'That’s a big decision, I need some time to think about it\' Enter NO for  \'Woah, sorry buddy, I’m just lost, I’m gonna have to bounce\'')
                elif answer == 'BACK':
                    print('You scramble back to the surface and try to forget what just happened. You continue towards FBI HQ, and wait for your agent at their desk')
if start == 'HELP':
helper()

I have checked that I am using the right input, changed elifs to ifs nothing else came to mind that could be the issue any help appreciated

Aucun commentaire:

Enregistrer un commentaire