14/14 How to Add 50 to the number stored under the 'gold' key?


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

}

inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']
inventory['pouch'].sort()

inventory['pocket']=['seashell','strange berry','lint']
inventory['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold']=50
print inventory


Oops, try again. Make sure to add 50 to the gold total!


#2

This line:

inventory['gold'] = 50

sets this value to 50. You don't want to set it to the new value, you only want to add to it 50.

You can use operator +:

inventory['gold'] = inventory['gold'] + 50

or combined operator +=:

inventory['gold'] += 50

#3

I made it this way:
inventory['gold'] = 550


#4

Well, this is kind of cheating, but it works in this exercise :smile:


#5

:joy: :joy: :joy: :joy: :smile: :smile: :smile: :smile: :grinning: :grinning: :grinning: :grinning:


#6

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'

inventory['pouch'].sort()

Your code here

inventory['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold'] = 500 + 50
print inventory


#7

QUESTION:

Why is that ((( inventory ['gold'] = 500 +50 ))) is written this way and not
this way [ 500 + 50 ]?

Thank you


#8

Syntax error:

File "python", line 15
inventory['gold']+=50
^
SyntaxError: invalid syntax