14. It's dangerous to go alone! take this


#1



https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/2/5?curriculum_id=4f89dab3d788890003000096#


File "python", line 14
'pocket' : ['seashell', 'strangeberry', 'lint']
^
IndentationError: unexpected indent


I honestly aren't sure why i'm getting this error..


inventory = {
'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'], 
'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']=inventory['gold']+50


#2

I also get this message popping up everytime I run this code..

Oops, try again. Did you accidentally delete the inventory dictionary? Click Reset Code to get back to the original code.


#3

Look at the arrow in the error. they're telling you that you have an unnecessary indent. It can happen when you press the spacebar on a line of code without noticing.


#4

hmmm... I've changed the code to this

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

Your code here

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

and my error is

File "python", line 14
'pocket' : ['seashell', 'strange berry', 'lint']
^
SyntaxError: invalid syntax

and the message is
Oops, try again. Did you accidentally delete the inventory dictionary? Click Reset Code to get back to the original code.


#5

The arrow appears below lint' ?


#6

It looks like you are creating pocket as if the code was still inside the declaration of inventory.
What you need to do is use the same syntax as where the provided code adds the 'burlap bag' key.
Hope this helps.


#7

you need to put in inventory:
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf'],
'pocket' : []


#9

Thank you!, it has really helped!


#10

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