I need help, please


#1



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


The error message is "Did you accidentally delete the inventory dictionary? Click Reset Code to get back to the original code."

I am confused about how I can remove/add the content of list.


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

inventory['backpack'].sort()
# Adding a key 'burlap bag' and assigning a list to it
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']
inventory.remove('dagger')
inventory.append(50)
# Sorting the list found under the key 'pouch'
inventory['pouch'].sort() 

# Your code here
inventory.append9('pocket')


#2

this code has so many mistakes:

'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']

missing , at the end

inventory.remove('dagger')

dictionary has no dagger, the backpack has

inventory.append(50)

append is a method to append to lists, inventory is not a list and neither is gold

inventory.append9('pocket')

typo


#3

Thank you for correcting me.

Now I have wrotten the code on this link:
https://www.codecademy.com/courses/python-beginner-en-pwmb1/2/5?curriculum_id=4f89dab3d788890003000096#

Why does it alert that "name 'backpack' is not defined"


#4

the link checks for user and loads that user code, so if i click the url, i will just get my own code. Please copy paste your code to the forum


#5

inventory = {
'gold' : 550,
'pouch' : ['flint', 'twine', 'gemstone'],
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf'],
'pocket' : ['seashell', 'strange berry','lint']
}

inventory['backpack'].sort()

inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']
backpack.remove('dagger')

inventory['pouch'].sort()

inventory.append('pocket')


#6

here:

backpack.remove('dagger')

backpack is part of inventory dictionary.

what did i say about append:

inventory.append('pocket')

a method for lists, inventory is not a list.


#7

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