Why is this syntax invalid?


#1

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


#2

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


#3

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.


#4

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.


#5

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