Python Forum

Full Version: Output in for LOOP iterated
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,
I am a beginner in Python and I am using PyScripter. Can someone help me why in this simple for loop example my output result is iterated. I expect only Total=80

prices=[10,20,50]
total=0
for item in prices:
        total= total + item
        print(f"Total:  {total}")
Error:
>>> Total: 10 Total: 30 Total: 80 >>>
Correct the indentation. Print is currently part of the for-loop body. It should be after and outside the for-loop.