Dangerous to go alone! take this


#1


problem

they instruct me to add(some numbers to a specific key in a dictionary list)
lets assume I need to add 50 to 'int' key in my for_example dict
i tried something like this
for_example['int'] = 50
can you help?


for_example = { 
                     'int' = 500 
}


#2

this:

for_example['int'] = 50

will add key 'int' to dictionary with value of 50 to for_example dictionary

this:

for_example = { 
                     'int' = 500 
}

will create a dictionary (for_example) with 'int' key and a value of 50, however, for this, after the key there should be a colon not a equal sign


#3

uhmmm ,
then
i need to add 50 to the

'int' = 500

how am I suppose to that? do you know?

this is the exact intructions
"Add 50 to the number stored under the 'gold' key"


#4

you need to add 50 to the value of 'gold' key

we can get the value of gold using:

print inventory['gold']

we can assign a new value to gold using:

inventory['gold'] = "new value"

To update a value, we can simply assign new value + current value to inventory['gold']


#5

UPDATE thats the word.
right now what I get is
I cant do this

inventory['int'] = 50
because it'll only make a new key to the dict[for_example]

you said "To update a value, we can simply assign new value + current value to inventory['gold']"
and thats what i need to know

so far a tried many changes to make it work, like so
inventory['gold'] = +50[0]
inventory['gold'] + 50
inventroy['gold'][0] = +50
inventroy['gold'][0] +50

and totally out of ideas
help me out :frowning:


#6

look how we update a variable:

example = 5
example = example + 5

see? You could use the same trick to update the gold value


Why is 'gold' wrong please help. Says syntax error
#7

oh i see i just need to repeat the instance.
something like this
inventory['gold'] = inventory['gold'] +50
i got it
thanks man for helping me :slight_smile:


#8

yes, do you also understand why? we want to assign a new value to inventory['gold'], which is the current value + 50


#9

yup at least I see the logic behind it
its just that im out of ideas how do to do it properly
ty ty :smile:


#11