Python Forum
Output in for LOOP iterated - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Output in for LOOP iterated (/thread-22557.html)



Output in for LOOP iterated - Renym - Nov-17-2019

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 >>>



RE: Output in for LOOP iterated - perfringo - Nov-17-2019

Correct the indentation. Print is currently part of the for-loop body. It should be after and outside the for-loop.