Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For Loop
#1
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.
Yoriz write Nov-02-2022, 09:01 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
For Loop - by siddharth - Nov-02-2022, 08:33 AM
RE: For Loop - by Yoriz - Nov-02-2022, 09:04 AM

Forum Jump:

User Panel Messages

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