Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
名称错误:全局名称';对象';不是由Python定义的_Python_Python 2.7_Nameerror_Function - Fatal编程技术网

名称错误:全局名称';对象';不是由Python定义的

名称错误:全局名称';对象';不是由Python定义的,python,python-2.7,nameerror,function,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 ch

我做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()
当我运行它时,我可以进入大房间,然后我键入DOORE one以到达DOORE one()。我想它应该到达def房间并从那里出发。除了我得到

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
房间里有一个手电筒,用微弱的光线照亮房间。有人介绍你
还有三扇门。你走哪条路?还是回去
回溯(最近一次呼叫最后一次):
文件“flue.py”,第78行,在
开始()
文件“flue.py”,第72行,在开始处
大房间
文件“fleed.py”,第21行,在big_room中
一号房间
文件“fleed.py”,第38行,在房间一
room1==原始输入(“>”)
NameError:未定义全局名称“room1”

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

您的代码中有一行:

room1 == raw_input(">")
你是说这个吗

room1 = raw_input(">")

我想是的!就是这样,这是有道理的。我肯定我以前犯过这个错误,它终于在这里做了些什么。在去掉另一个等号后,它就起作用了。非常快。谢谢。仅供参考:您的错误位于回溯的倒数第二行:P(python的优点之一:大多数时候,回溯会准确地告诉您做错了什么)您是对的!这次只是错过了。我会仔细看的!