10/9 Something of value?


Could someone explain this to me ?

total = 0 
for key in prices:
    total = prices[key] * stock[key] + total
print total

The above code is correct , but i am wondering why there is need to add total to prices[key] * stock[key] it should function well without total too ? But without total the answer is zero.
Any help is appreciated


Well if you are going to increase the total, then you better include the total itself in the result.


Got that thanks for your help !!!!


It's common to want to increases somithing, usually it's written as

a += 5

Which clearly reads as a is increased by 5