It's Dangerous to go alone! Take This; What is wrong with my code?!?!


#1

I have no idea what is wrong with my code. I have waited at least a month before resorting to the Q&A forums. Could someone tell me what is wrong?

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'] += 50

The error reads:
File "python", line 5
'pocket' : ['seashell', 'strange berry', 'lint']
^
SyntaxError: invalid syntax
indent preformatted text by 4 spaces

Also, here is the message that pops up when I click 'save and submit':
Oops, try again. Did you accidentally delete the inventory dictionary? Click Reset Code to get back to the original code.


#2

Missing comma after this member.


#3

You have to add the 'pocket' key like this

# 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']

at least that worked for me.


#4

IT WORKED!!! Thank you so much!


#5

you helped me I helped you lol np


#6

Oh. i stop on this +=50 :open_mouth:


#7

LOL :joy:Thanks so much for the help!


#8

That inventory['gold'] += 50 was a hit for me too.:slightly_smiling:


#9

i stopped on the gold part, was trying to o it with .append, gawd that was stupid


#10

The += 50 thing helped me, too. Is there another way to add ints? I tried ".add" and ".sum" and even ".append".


#11

i dont think there is any other way


#12

When a value is a member element of a data structure, we have to access the element to modify the value.

inventory['gold']

looks like a reference, but to the compiler, it is a value, 500. To change that value, we operate on it directly:

inventory['gold'] += 50

Now the value is 550.

The only other way to change it is to assign a new value, but that wipes out the old one. We might not wish to do that in most cases. This example adjusts the value, in place.