Python Lists and Dictionaries


#1



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

Oops, try again. Make sure to add 50 to the gold total!

the error messages may not express all my error, I mistake the dic and list, so I can not correctly answer.
who can kindly tell me Is there a correct and more simple way to solving it? thanks a lot!


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']=[500+50]


#2

here..
inventory['gold']=[500+50] (why're you putting the value in a list? )

You have to increase value of gold key by 50

suppose..
x is an integer.

x = 40

I want to increase its value by 30, I'd do this..
x = x + 30

Keep in mind that there you have to use key gold that have corresponding value 500 now.
You need to increase it's value by 50.


#3

I know,I don't know how to increase the 50? I used to try..

inventory['gold']=[550]

How can I show the calculating process?


#4

Thanks a lot, I succeed.

inventory['gold']+=50

:grin:


#5

How did you figure this out? I never would've guessed += to add the numbers based on everything learned.

Good job, by the way!


#6

I guess it likes:
inventory['gold']=50+inventory['gold']


#7

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