2016-10-04 5 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 ''은 파이썬의 dict 리터럴에서 유효한 구문이 아닙니다. – skovorodkin

+0

또한, 이들은 _dictionctor_가 아닌 _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

, 문제는 당신이 사용하는 것입니다 = 대신 : 사전 항목을 할당합니다.

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 

문제에서 그 파이썬 점을 볼 수있을 거라고했다 오류".

관련 문제