2016-11-06 6 views
0

私はPythonでエスケープルームゲームを作成しようとしています。
pycharmでコードを実行すると、プロセスは「プロセスは終了コード0で終了しました」と終了します。"if"文の中で関数が実行されないPython 3

機能の定義に何か問題はありますか?ここで
は、(その少し長い)私のコードです:

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() 

私はそれが最後の「if」文のかもしれないと思うが、私は肯定的ではありませんよ。

+0

基本的に終了しないでプログラムを実行し続けたいですか? –

+0

これを素早くデバッグするには 'main_choice()'を呼び出した後にデバッグプリントを配置して、まず 'choice'を何かに割り当てるようにします。 – scrappedcola

答えて

1

あなたmain_choice機能にchoice = input("Make your choice: ")choice == input("Make your choice: ")を変更する必要があります。

def main_choice(): 

    print("1. Examine door") 

    print("2. Examine painting") 

    print("3. Examine desk") 

    print("4. Examine bookshelf") 

    choice = input("Make your choice: ") 

そうでない場合choice変数はまだNoneなり、if choice == "1":は常にFalseになります。

1

あなたは書く必要があります。

choice = input("Make you choice: ") 

いうより:

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

ダブル兆しが値を変更するのではなく、ブール値を返すと等しいです。

関連する問題