9. Something of Value



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


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


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


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


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


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


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


That is what I did. It works flawlessly.