9. Something of Value


#1


https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/1/4?curriculum_id=4f89dab3d788890003000096#


total = 0 

for key in prices :
  ind_total = prices[key] * stock[key]
  print ind_total
  
  
total = sum(ind_total) 
print total

i can't get the right code to print the total , please help me out


#2

don't use sum(), its a built in function for an iterable like a list

you have a print statement which shows you that ind_total doesn't increase, it just updates/re-assign

add the total of prices[key] * stock[key] to the value already stored in ind_total


#3

i still can't figure out how to code it :frowning:


#4

if we want to update a variable, we can store the current value of variable + what we want to add in a new variable with the same name


#6

Got it ! total = total + ind_total
Thanks alot for your help


#7

Here is what I think: ind_total should be replaced to total where total increments like this: total += stock[key] * prices[key] Take note of the += okay? After doing that, you can now print total


#8

the fact that you got it also means you understand, very pleased to see that :slight_smile:


#9

That is what I did. It works flawlessly.


#10