NameError:全局名称'object'未定义Python

时间:2015-07-08 00:44:28

标签: python python-2.7 nameerror function

我已经做了几个月的Python,并且在定义函数方面遇到了麻烦。我只是创造了一个小型的CYOA迷宫,那里有多个房间,玩家必须来回走动。它适用于某些功能但我得到NameError:全局名称'object'未定义错误。

#Main room
def big_room():
    print """You arrive inside a huge square room. You are presented with 
3 giant wooden doors. Which door do you choose?Or you can Leave."""


    room = raw_input(">")

    if room == "door one":
        print"You open door one and walk in."
        room_one()
    elif room == "door two":
        room_two()
    elif room == "door three":
        print """You go toward door three and attempt to pull it.
The door opens loudly and you walk in."""
        room_three()
    elif room == "Leave":
        dead("You decide to walk away and get eaten by a Jaguar")
    else:
        print "What are you saying?." 

def room_one():
    print """The room has one torch lighting the room with a faint glow. You are presented
with another three doors. Which way do you go? or go back"""


    room1 == raw_input(">")

    if room1 == "door one":
        print "Test"
    elif room1 == "door two":
        print"Test"
    elif room1 == "door c":
        hole()
    elif room1 == "go back":
        big_room()
    else:
        print "test me"

def hole():
    print "You take a step forward and the floor below you caves in; you fall in and die."
    dead()


def dead(why):
    print why,"Game over!"
    exit(0)


raw_input("Press Enter to Continue")

def start():
    print """After a long time of walking through a thick jungle,
you arrive at a temple covered in foliage and a narrow entrance.
go inside. or Leave"""

    while True:
        temple = raw_input(">")

        if temple =="go inside":
            big_room()
        elif temple == "Leave":
            dead("You decide to walk away and get eaten by a Jaguar")
        else:
            print "What are you saying?"

start()

当我运行它时,我可以进入big_room然后我输入第一个门来到door_one()。我假设它应该去def room_one()并从那里运行。我明白了

The room has one torch lighting the room with a faint glow. You are presented
with another three doors. Which way do you go? or go back
Traceback (most recent call last):
  File "flee.py", line 78, in <module>
    start()
  File "flee.py", line 72, in start
    big_room()
  File "flee.py", line 21, in big_room
    room_one()
  File "flee.py", line 38, in room_one
    room1 == raw_input(">")
NameError: global name 'room1' is not defined

当我输入一些像big_room()中那样的输入时,我确信我会定义它。任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

您的代码中有这一行:

RefererHost

你的意思是?

room1 == raw_input(">")