I got stuck!


#1



 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() 

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

I canĀ“t do the last point!
Add 50 to the number stored under the 'gold' key


#2

Your syntax is wrong! Write it with += instead of =+.
Hope this helps :slight_smile:


#3

@maverba ,

If you add this at the end of your code, as a test ...

print inventory['gold']

... you will get this output ...

50

That is because +50 is equivalent to 50. Python interprets this ...

inventory['gold']=+50

... as being the same as this ...

inventory['gold'] = +50

... which is an assignment of +50 to inventory['gold'], rather than an augmented assignment that increases the value of inventory['gold'] by 50. Technically what you have is valid syntax, but it performs the wrong operation for this exercise.


#4

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