0

約 2 週間前に Python 3 の学習を始めたばかりです。基本的なテキスト ゲームを作成することにしました。ただし、修正できないコードのバグに遭遇し、他のどこにも見つけられません。ゲームを実行すると (コードを受信)、次のエラーが発生します。

Welcome to the room. This is the room in which this game takes place

Press enter to continue.

What would you like to do? Type HELP for your options

HELP

Traceback (most recent call last):


File "C:/Users/Michael/Desktop/mess.py", line 35, in <module>
inputFunc()


File "C:/Users/Michael/Desktop/mess.py", line 7, in inputFunc
inputExam()


File "C:/Users/Michael/Desktop/mess.py", line 9, in inputExam
if (inSet == "LOOK"):

NameError: global name 'inSet' is not defined

これが私のゲームのコードです:

# functions:
def youLose():
    print("You lost.")
def inputFunc():
    print("What would you like to do? Type HELP for your options")
    inSet = input()
    inputExam()
def inputExam():
    if (inSet == "LOOK"):
        print("You are in a room. There is a door in front of you. You have a key in your hand. There is a slip of paper on the ground.")
        inputFunc()
    elif (inSet == "HELP"):
        print("Use LOOK to examine your surroundings. Use OPEN to open things. Use EXAMINE to examine things. Use QUIT to quit the game. Remember to use ALL CAPS so the processor can understand you")
        inputFunc()
    elif (inSet == "EXAMINE PAPER"):
        print("The paper reads: 'There is only one winning move'")
        inputFunc()
    elif (inSet == "OPEN DOOR"):
        print("You open the door using your key. There is a bright light on the other side, blinding you. You feel a familiar feeling as you realize that you have died.")
        input("Press enter to continue.")
        youLose()
    elif (inSet == "EXAMINE DOOR"):
        print("A simple oaken door.")
        inputFunc()
    elif (inSet == "QUIT"):
        print("You hear a clicking of gears. You realize that the only winning move is not to play. You Win!")
    elif (inSet == "EXAMINE KEY"):
        print("A small, brass key that looks to fit the lock on the door.")
        inputFunc()
    else:
        print("Syntax Error")
# base:
print("Welcome to the room. This is the room in which this game takes place")
input("Press enter to continue.")
inputFunc()
4

1 に答える 1