Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to decrease input
#1
I'm very new to coding so my apologies if I'm saying any of this wrong. I am trying to write a code for this prompt:

A company has 3 divisions. After inputing the sales for each division across 4 quarters, I want to print the average sales for each division. Below is the code:

divisions = 3
while divisions > 0:
    total = 0
    quarters = 4
    while quarters > 0:
        sales = float(input("Enter sales: "))
        total += sales
        quarters -= 1
    average = total / 4
    divisions -= 1
    print("The average for division", divisions + 1, "is $", format(average, '.2f'))
Here is my problem. When I run the code, it prompts me to "Enter sales". And then after I do it four times, it tells me the average. How can I write this code so that it will ask me to enter the sales for Division 1 Quarter 1, Division 1 Quarter 2, Division 2 Quarter 2 etc. and then it will print "The average sales for Division 1 were...", "The average sales for Division 2 were..."

THANK YOU
buran write Apr-14-2021, 03:16 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
How to decrease input - by Yankees1111 - Apr-14-2021, 02:13 PM
RE: How to decrease input - by ibreeden - Apr-14-2021, 02:54 PM
RE: How to decrease input - by BashBedlam - Apr-14-2021, 04:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to decrease latency while recording streaming video. unicorn2019 0 1,269 Nov-15-2021, 02:12 PM
Last Post: unicorn2019
  increase and decrease a slice value? KEYS 2 2,112 Nov-10-2020, 11:35 PM
Last Post: KEYS

Forum Jump:

User Panel Messages

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