Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Output in for LOOP iterated
#1
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 >>>
Reply


Messages In This Thread
Output in for LOOP iterated - by Renym - Nov-17-2019, 07:51 PM
RE: Output in for LOOP iterated - by perfringo - Nov-17-2019, 09:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The way to chase how the set of integer is iterated in mutating loop khei4 4 833 May-26-2023, 09:17 AM
Last Post: Gribouillis
  using 'while loop' output going into infinite loop... amitkb 2 1,976 Oct-05-2020, 09:18 PM
Last Post: micseydel
  sports Stats > table output loop problems paulfearn100 3 2,527 Jul-22-2020, 03:21 AM
Last Post: c_rutherford
  Print output in single file using pramika loop deepakkhw 1 2,086 Jul-11-2020, 11:57 AM
Last Post: j.crater
  output list reducing each time through loop 3Pinter 6 3,533 Mar-19-2019, 01:31 PM
Last Post: perfringo
  Loops - new terminal output to file for each loop jm_ice 1 2,599 Dec-21-2018, 02:42 PM
Last Post: ichabod801
  A little unexpected output from a while loop linuxnoob 3 3,128 Jul-17-2018, 01:02 AM
Last Post: gontajones

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020