Every time when i execute below code by ‘Shift plus enter’ or ‘control plus enter’
for i in prices:
if prices[i] < 5:
money_spent = money_spent + (prices[i]*quantity[i])
money_spent = money_spent
it gives me answer every time answer by adding 24 to output.
I mean first time, when i execute it give me answer 24, which is ok.
Then when i again repeat same code in below cell, it gives result 48, by doing third time 72 and so on.
My question is how shall i execute the code in Jupyter note book so that every time, i execute it, it gives me result of 24 every time.
Thanks for reaching out.
You just need to add the following line to the beginning of your phrase.
money_spent = 0
In this way, every time you run the loop, you will start from money_spent with a value of 0, and you will not add 24 every time you execute the code cell.
Hope this helps.