It's Dangerous to Go Alone! Take This


#1



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


Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: name 'backpack' is not defined

Traceback (most recent call last):
File "python", line 15, in
NameError: name 'backpack' is not defined


Dagger to be removed


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

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


#2

backpack is a list inside a dictionary, so you need to use dictionary + listname to remove the dagger. I will let you think about the syntax, if you need more help let me know


#3

inventory['backpack'].remove('dagger')

error now says
Oops, try again. It looks like you did not add the "pocket" key.

and should i use print dictinoary name at the end of code..
(i.e) print inventory


#4

you add pocket here:

inventory['Pocket']

but the checking script is case sensitive (pocket vs Pocket), if a new error arises it is alright to take the time to try to understand where the new error comes from


#5

inventory['gold'] = '50'

again im getting error in this..
Oops, try again. Make sure to add 50 to the gold total!

but i made the code according to previous exercises ,..


#6

you don't add 50 gold, you set the total amount of gold to 50, two completely different things


#7

Oh yeah.. the instruction was to add 50 rite.. let me try ..


#8

inventory['gold'] = ['50']

is this correct


#9

nope, not correct. If i have a variable:

test = 10

i can update the variable:

test = test + 10

or i can shorten it with +=, the same goes for a value in a dictionary.


#10

so gold = gold +10 or
inventory = inventory + 10

i cant understand bro


#11

i showed you for a variable, you have a dictionary. Take a second to think about it. This syntax you had:

inventory['gold'] = '50'

i just showed you how to update, rather then set (by using = and +), take time to think about it, if you need it


#12

brother please help i could not get.. i tried many things :frowning:


#13

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

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

what mistake in this

i get the following error
File "python", line 16
SyntaxError: can't assign to function call


#14

inventory['gold'] = 550 
      OR
inventory['gold'] = 500 + 50

how stupid i am..

by the way is the above correct


#15

why not simply do what i showed with the variable:

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

#16

yes , your code seems professional =D