2016-10-04 63 views
0

我正在为我正在编写的程序构建一些目录,但是在游戏中使用时并且没有使用它们时,它们会一直出错。每行都抛出相同的错误(Syntax Error: invalid syntax),我想知道为什么。线是:目录 - 为什么这个错误?

secretpassageunearthed = 'No' 
pickedup = {'broom': '0', 'rope': '0', 'torch': '0', 'coffin': '0', 'skeleton' = '0', 'key2': '0', 'rock': '0', 'key1': '0', 'mailbox': '0', 'instructions': '0', 'letter': '0', 'key3': '0', 'oar': '0', 'boat': '0', 'red button': '0', 'eaglenest': '0', 'faberge egg': '0', 'trophy case': '0', 'facial': '0', 'gun': '0', 'safe': '0', 'diamond ring': '0', 'junk': '0', 'combination': '0', 'egg': '0', 'flashlight': '0', 'cork': '0', 'bottle': '0', 'oil': '0', 'crown': '0', 'shovel': '0', 'knob': '0', 'twinkies': '0', 'scanner': '0', 'toychest': '0'} 
#has the player been in the room? 
beenin = {'frontdoor': '0', 'forest': '0', 'forest2': '0', 'forest3': '0', 'forest4': '0', 'lakeshore': '0', 'garden': '0', 'shed': '0', 'lake': '0', 'farshore': '0', 'cliff1': '0', 'cliff2': '0', 'cliff3': '0', 'cliff4': '0', 'clifftop': '0', 'frontsteps': '0', 'frontlawn': '0', 'gate': '0', 'sittingroom': '0', 'livingroom': '0', 'pantry': '0', 'foyer': '0', 'trophyroom': '0', 'hall1': '0', 'diningroom': '0', 'kitchen': '0', 'elevatorup': '0', 'hall3': '0', 'hall2': '0', 'masterbed': '0', 'closet': '0', 'nursery': '0', 'bath': '0', 'guestroom': '0', 'study': '0', 'secretroom': '0', 'servantdining': '0', 'servantbath': '0', 'servantroom': '0', 'boilerroom': '0', 'mechanicalroom': '0', 'winecellar': '0', 'deadend': '0', 'torturechamber': '0', 'morgue': '0'} 
maxweight = 50 
weights = {'broom': 5, 'rope': 8, 'torch': 5, 'coffin': 40, 'skeleton': 9, 'key1': 2, 'key2': 1, 'rock': 4, 'instructions': 0, 'mailbox': 60, 'letter': 1, 'gargoyle': 60, 'key3': 1, 'blockade': 60, 'oar': 5, 'boat': 30, 'button': 1, 'eagle nest': 60, 'faberge egg': 10, 'trophy case': 60, 'book': 3, 'facial': 1, 'gun': 3, 'safe': 60, 'diamondring': 5, 'junk': 1, 'combo': 1, 'egg': 1, 'flashlight': 3, 'oil': 4, 'bottle': 3, 'cork': 1, 'chandelier': 60, 'crown': 5, 'shovel': 5, 'knob': 3, 'twinkies': 2, 'pot of gold': 30, 'painting': 20, 'scanner': 60, 'toychest': 55} 

任何帮助他们为什么他们错误了,将不胜感激。

+2

''skeleton'='0''在Python的dict文字中不是合法的语法。 – skovorodkin

+0

另外,这些是_dictionaries_,而不是_directories_。 –

回答

0

不能使用=在字典

变化=分配给:,这应该工作:

secretpassageunearthed = 'No' 
pickedup = {'broom': '0', 'rope': '0', 'torch': '0', 'coffin': '0', 'skeleton' : '0', 'key2': '0', 'rock': '0', 'key1': '0', 'mailbox': '0', 'instructions': '0', 'letter': '0', 'key3': '0', 'oar': '0', 'boat': '0', 'red button': '0', 'eaglenest': '0', 'faberge egg': '0', 'trophy case': '0', 'facial': '0', 'gun': '0', 'safe': '0', 'diamond ring': '0', 'junk': '0', 'combination': '0', 'egg': '0', 'flashlight': '0', 'cork': '0', 'bottle': '0', 'oil': '0', 'crown': '0', 'shovel': '0', 'knob': '0', 'twinkies': '0', 'scanner': '0', 'toychest': '0'} 
#has the player been in the room? 
beenin = {'frontdoor': '0', 'forest': '0', 'forest2': '0', 'forest3': '0', 'forest4': '0', 'lakeshore': '0', 'garden': '0', 'shed': '0', 'lake': '0', 'farshore': '0', 'cliff1': '0', 'cliff2': '0', 'cliff3': '0', 'cliff4': '0', 'clifftop': '0', 'frontsteps': '0', 'frontlawn': '0', 'gate': '0', 'sittingroom': '0', 'livingroom': '0', 'pantry': '0', 'foyer': '0', 'trophyroom': '0', 'hall1': '0', 'diningroom': '0', 'kitchen': '0', 'elevatorup': '0', 'hall3': '0', 'hall2': '0', 'masterbed': '0', 'closet': '0', 'nursery': '0', 'bath': '0', 'guestroom': '0', 'study': '0', 'secretroom': '0', 'servantdining': '0', 'servantbath': '0', 'servantroom': '0', 'boilerroom': '0', 'mechanicalroom': '0', 'winecellar': '0', 'deadend': '0', 'torturechamber': '0', 'morgue': '0'} 
maxweight = 50 
weights = {'broom': 5, 'rope': 8, 'torch': 5, 'coffin': 40, 'skeleton': 9, 'key1': 2, 'key2': 1, 'rock': 4, 'instructions': 0, 'mailbox': 60, 'letter': 1, 'gargoyle': 60, 'key3': 1, 'blockade': 60, 'oar': 5, 'boat': 30, 'button': 1, 'eagle nest': 60, 'faberge egg': 10, 'trophy case': 60, 'book': 3, 'facial': 1, 'gun': 3, 'safe': 60, 'diamondring': 5, 'junk': 1, 'combo': 1, 'egg': 1, 'flashlight': 3, 'oil': 4, 'bottle': 3, 'cork': 1, 'chandelier': 60, 'crown': 5, 'shovel': 5, 'knob': 3, 'twinkies': 2, 'pot of gold': 30, 'painting': 20, 'scanner': 60, 'toychest': 55} 
0

正如其他人所说,问题是,你使用的=代替:分配字典项目。

当您看到的错误消息,您可能没有注意到,Python的是想确切地告诉你其中的错误是:

File "adventure.py", line 1 
    pickedup = {'coffin': '0', 'skeleton' = '0', 'rock': '0'} 
             ^
SyntaxError: invalid syntax 

如何看^在等号右边指着签名了吗?

+0

我想感谢大家发现错误。我对Python相当陌生,正在学习,Stack Overflow一直是非常宝贵的资源。再次感谢! :) – Adam

0

python style guide建议保留72行字符<。就个人而言,我的目标是78.如果你这样做,你的代码更容易阅读,作为奖励,它更容易发现问题。因此,举例来说,如果你的文件是

secretpassageunearthed = 'No' 
pickedup = {'broom': '0', 'rope': '0', 'torch': '0', 'coffin': '0', 
'skeleton' = '0', 'key2': '0', 'rock': '0', 'key1': '0', 'mailbox': '0', 
'instructions': '0', 'letter': '0', 'key3': '0', 'oar': '0', 'boat': '0', 
'red button': '0', 'eaglenest': '0', 'faberge egg': '0', 'trophy case': '0', 
'facial': '0', 'gun': '0', 'safe': '0', 'diamond ring': '0', 'junk': '0', 
'combination': '0', 'egg': '0', 'flashlight': '0', 'cork': '0', 'bottle': '0', 
'oil': '0', 'crown': '0', 'shovel': '0', 'knob': '0', 'twinkies': '0', 
'scanner': '0', 'toychest': '0'} 

你会看到蟒蛇点正是在这个问题

[email protected] ~/tmp $ python3 test.py 
    File "test.py", line 3 
    'skeleton' = '0', 'key2': '0', 'rock': '0', 'key1': '0', 'mailbox': '0', 
      ^
SyntaxError: invalid syntax 

你基本上说:“我写的代码是难以阅读,并不能找到错误”。