Why does this error message crop up and how do i correct my code?


it says " File "python", line 4
'backpack' = ['xylophone','dagger', 'bedroll','bread loaf'],
SyntaxError: invalid syntax"

ideally it would have sorted out my lists

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

# Adding a key 'burlap bag' and assigning a list to it
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']

# Sorting the list found under the key 'pouch'




Look up (google/other) syntax for dictionary literals, or just study your code for inconsistencies.

You need to develop an eye for this kind of thing.
If not immediately obvious, it might help to start with an empty dict ({}) and then adding one at a time


i added a ':' to both backpack and pocket but it still says
Traceback (most recent call last):
File "python", line 16, in
NameError: name 'backpack' is not defined


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