Can't add Gold value in It's dangerous to Go Alone!


Can't add the gold value in this manner.

inventory = {
    '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'

# Your code here
inventory['pocket']= ['seashell', 'strange berry', 'lint']

How to proceed from here?


append is a function to add something to a list, inventory is a dictionary. Just like you update a variable:

example = example + 50

you can update a dictionary the following way:

dictionaryName['keyName'] = dictionaryName['keyName'] + 50


if you want to overwrite the value of gold, you can use inventory['gold'] = 50


why would you want to do this? the exercise asks to add 50 gold, not overwrite


It's because inventory['gold'] is int not a list. Here he is trying to add to gold, not inventory.
It will work if gold was a list.


yea, i said that already:


Primo I didn't see the exercice, secundo I say clearly "if"

It was just an information.:slight_smile:


Thanks sir! Was really very helpful!!