Python Forum

Full Version: For Loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I have a for loop program for which want result.

Program:
prices = [10,20,30]
total = 0
for price in prices:
    total += price
    print(f"Total: {total}")
Result:
Output:
Total: 10 Total: 30 Total: 60
Is it possible to get result as Total : 60; I dont want Total: 10 & Total: 30 to appear.
At the moment the print happens inside the loop, think about how you could alter the code to make the print happen after the loop is finished.
Hint: indentation is key to what happens inside the loop.