10/9 Something of value?


#1

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


#2

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


#3

Got that thanks for your help !!!!


#4

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

a += 5

Which clearly reads as a is increased by 5