It's Dangerous to Go Alone! Take This


I’m pretty sure I understand this scenario now, but I just wanted to confirm my suspicions.
So in the exercise we are suppose to edit these multiple lists or dictionaries. In our “inventory” we have an integer(500) for ‘gold’. Now the exercise asks us to add 50 gold to that. I’ve listed below both what I originally wrote and then what codecademy kicked back to me as the correct code. Is my code, the first one, simply just re-writing ‘gold’ to 50? I was trying to add it as an item to the list. And anyways, the second is the correct. Thanks for checking!

inventory['gold'] = [50]
# corrected..
inventory['gold'] = inventory['gold']+50


Here, we just simply reassign 'gold' 's value to 50. We haven’t added to its current value.
So yes, 'gold''s value was rewritten to 50.

Here, we add (+) 50 to 'gold''s value, so now, inventory['gold'] = 550. If you want to see for yourself, you can just print inventory['gold'] and press the “run” button in the editor.


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