因此,我是第一年,虽然有一点编码经验,但是经验不足,我被赋予了制作基于文本的冒险游戏的任务。我的讲师给了我们一个模板并帮助我们开始使用,但是对于为什么这段代码导致shell出现NameError:名称“ direction”未定义,我感到困惑。有人可以帮忙第一年吗?
def print_menu_line(direction, leads_to):
"""This function prints a line of a menu of exits. It takes two strings: a
direction (the name of an exit) and the name of the room into which it
leads (leads_to), and should print a menu line in the following format:
Go <EXIT NAME UPPERCASE> to <where it leads>.
For example:
>>> print_menu_line("east", "you personal tutor's office")
Go EAST to you personal tutor's office.
>>> print_menu_line("south", "MJ and Simon's room")
Go SOUTH to MJ and Simon's room."""
print(rooms[room_livingRoom["exits"]])
direction = input("Which direction? ")
leads_to = input("Where do you want to go? ")
print("Go", direction, "to", leads_to)
print_menu_line(direction, leads_to)
您粘贴的代码中存在一些错误。这是我假设您的讲师给您的代码。