It's Dangerous to Go Alone! Take This


#1

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')
inventory['gold'].append(50)

I had written my code as instructions. but i didn't get result. when i click on save&submit it was showing like this. Can any one help me to solve this program.

Oops, try again. Check for keys without values or misspelled keys!


#2

gold corresponds to a single numerical value, 500. It is not a list, just a member of a dictionary. To modify its value,

+= 50

#3

this:

inventory={
    'pocket' : ['seashell', 'strange berry', 'lint']
    }

will not add pocket to inventory. It will overwrite inventory and now only contain pocket, look:

inventory={
    'pocket' : ['seashell', 'strange berry', 'lint']
    }
print inventory

not really what you should do, look in the instructions on how to add to a dictionary.


#4

inventory['gold'] += 50

is this way of writing code correct.could you send correct program how to write


#5

That is how you would increase the value by 50, yes.


#6

did you see what i wrote?

If you need more help, post an updated version of your code


#7

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

inventory['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold'] += 50

this is my program.could you please help me in solving this program. when I click on save&submit it shows me like this.

Traceback (most recent call last):
File "python", line 20, in
KeyError: 'backpack'

Oops, try again. Check for keys without values or misspelled keys!


#8

the point of this print statement:

print inventory

was to show you that you overwrote your inventory dictionary.

I was helping, not coding your solution. You will still have to change it so you add pockets to inventory rather then overwriting

Did you even read what i told you? it doesn't feel like, it feels like you just copied the code


#10

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