File "python", line 3 'gold': 500, ^


#1



Python Lists and Dictionaries

File "python", line 3
'gold': 500,
^
SyntaxError: invalid syntax


I expect the program to say success


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

# 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'
inventory['pouch'].sort() 
inventory['pocket'].sort()
inventory["backpack"].remove("dagger")
inventory['gold'].add(50)


#2

Problem1.
You missed comma after first key-value pair

Problem2.
inventory['pocket'].sort()

You had to sort this list .. inventory["backpack"]

Problem3

We do not have any method called add() on integers

so you need to use general method to increment value by 50.

Like this..

If I had to increase the value of x by 50 I'd do this..

x = 45
x = x + 50

#3

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