简体   繁体   中英

Function not Running inside an “if” statement Python 3

I'm attempting to write an escape room game in Python.
When I run the code with pycharm the process ends with "process finished with exit code 0."

Is there something wrong in the defining of the functions?
Here is my code (its a bit lengthy):

choice = None

def main_choice():

    print("1. Examine door")

    print("2. Examine painting")

    print("3. Examine desk")

    print("4. Examine bookshelf")

    choice == input("Make your choice: ")


def door():

    print("1. Try to open door")

    print("2. Take a closer look")

    print("3. Go back to where you were.")

    door_choice = input("What now? ")

    if door_choice == "1":

        print("The door is too heavy to open with your bare hands.")

        door()

    if door_choice == "2":

        print("There is a red light above the door, but it seems to have no purpose.")

        print("You notice a 9 key keypad next to the door. It looks like it will accept a 3 digit code.")

        keypad_code = input("Would you like to enter a code?").lower

        if keypad_code == " yes":

             guess = input("ENTER CODE: ")

             if guess == complete_key:

             print("The light turns green and you hear the sound of a mechanical lock unlocking. The door opens.")

             print("YOU WIN!!!")

        if guess != complete_key:

             print("Wrong code.")

             main_choice()

    if door_choice == "3":

        main_choice()

    else:

        print("You didn't answer")


main_choice()

if choice == "1":

    print("You walk to the door")

    door()

I think that it might be the last "if" statement, but I'm not positive.

You need to change choice == input("Make your choice: ") to choice = input("Make your choice: ") in your main_choice function:

def main_choice():

    print("1. Examine door")

    print("2. Examine painting")

    print("3. Examine desk")

    print("4. Examine bookshelf")

    choice = input("Make your choice: ")

Otherwise the choice variable will still be None and if choice == "1": will always be False.

You should write:

choice = input("Make you choice: ")

rather than:

choice == input("Make you choice: ")

Double equals signs return a boolean rather than changing a value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM