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


#1




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'
inventory['pouch'].sort() 

# Your code here
inventory['pocket']= ['seashell', 'strange berry', 'lint']
inventory['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold'].append(50)

How to proceed from here?


#2

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

#3

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


#4

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


#5

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.


#6

yea, i said that already:


#7

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

It was just an information.:slight_smile:


#8

Thanks sir! Was really very helpful!!