Changing the value of integer key (gold in lesson 14)


#1



I can't seem to figure out a way to directly add the int key of '50' to the value associated with 'gold'. Reassigning the key to '550' works just fine, as shown below in my mess of a code.
Who can show me how to actually add 50 to the value instead of taking the lazy way out? Thanks...


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']
inventory['pocket'] = ['seashell', 'strange berry', 'lint'] #task number one & two: add pocket to inventory, as well as assigning key to list. 

# Sorting the list found under the key 'pouch'
inventory['backpack'].sort() 
#task number three
inventory['pouch'].sort() 
inventory['backpack'].remove("dagger")
#task number four
inventory['gold'] = 550
#task number 5
# Your code here


#2

Hi, @mgallotta,

Instead of this ...

inventory['gold'] = 550

... perform the addition explicitly.


#3

can you show us how you tried to attempt to increase?

here is an example:

x = 5
x = x + 5

#4

that is exactly the question he is asking?


#5

@mgallotta ,

Use the same pattern that @stetim94 's example demonstrates.


#6

inventory["gold"] = 500 + 50

totally works. but I'm looking for a way to add fifty w/o actually calling on 500. is that possible?


#7

Yes, @stetim94 showed us this for a variable, x, and 5 ...

x = x + 5

You can do something similar with inventory['gold'] and 50.

This pattern also works ...

x += 5

#8

Perfect. The '+=' is what I was looking for. Thanks!


#9