It's dangerous to go alone


#1

So doing this exercise and already past it by changing my code but curious why my initial idea doesn't work.

The assignment is to:

Add 50 to the number stored under the 'gold' key

When i use the .append method it doesnt accept it and gives me

File "python", line 17
inventory['gold'].append(+= 50)
^
SyntaxError: invalid syntax

why can't I do it this way?


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

inventory['gold'].append( += 50)


#2

because .append() is a method to append an item to a list, 500 is a integer.


#3

Ok, thanks for the explaination


#4

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