2016-10-04 7 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

また、それらは_directories_ではなく_dictionaries_です。 –

答えて

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は、7238文字を使用することを推奨しています。<個人的には、私は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 

問題でそのPythonのポイントを参照してくださいねでしたエラー"。

関連する問題