Why is this syntax invalid?


inventory = {
'gold' : 500, 50
'pouch' : ['flint', 'twine', 'gemstone'] # Assigned a new list to 'pouch' key
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']
'pocket' : ['seashell', 'strange berry', 'lint']

File "python", line 3
'pouch' : ['flint', 'twine', 'gemstone'] # Assigned a new list to 'pouch' key
SyntaxError: invalid syntax


There is the error. Remove the , 50 and use a statement to update the value for gold.


Yes, I've finished the lesson and added the 50 as you should have. But, that had was not the syntax error that was being thrown. I reset the code and submitted it several times and eventually it stopped throwing the error, therefore I believe it was just a problem in the lesson itself, before any input.


If you look at the message, it shows a Python syntax error. Where the carat is positioned is where parsing stopped. That means the error is belore that line, namely in the line above. Values cannot be written as comma separated unless they are in a container.

>>> my_dict = { 'gold': 500, 50 }
SyntaxError: invalid syntax

Syntax errors are not raised during a run. They get raised when the script is being parsed.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.