Why my code doesn't work


#1

Who knows why my code doesn’t work online, but can run well in IDLE? help

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

inventory[‘pocket’] = [‘seashell’,‘strange berry’,‘lint’]
inventory[‘backpack’].remove(‘dagger’)
inventory[‘backpack’].sort()

del inventory[‘backpack’]
inventory[‘gold’] = inventory[‘gold’]+50


above code can pass the test. good luck

#2

Could you provide the link of the exercise ??


#3

https://www.codecademy.com/courses/learn-python/lessons/


#4

I have fixed this problem, thank you.


#5

May i suggest you re-edit your Original post
then selecting the code
and click on :Preformatted text </> Button
Your code will Not being interpreted by the editor
and therefor would be more readable…
try it…

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
inventory['pocket'] = ['seashell','strange berry','lint']
inventory['backpack'].sort()
inventory['backpack'].remove('dagger')

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


#6

The link you gave returns a HTTP 404 error !!!


#7

Your code is awesome. Thank you for your suggestion. Pretty cool. Thanks a lot.


#8

It was the code from your post…
please re-edit your Original post.


#9

Ok, I just re-edited it for sharing with everyone. it works.


#10

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