1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Katarina [22]
3 years ago
6

Question 1. (50 points) 1.Write a program that computes information related to a sequence of entries regarding age of customers.

The user is asked to enter the age of each customer until they wish to stop. The program then computes and displays the following:2. The number of customers in total and in each age group3. The average age for all customers.4. The youngest and oldest customer.4. The range of age (range = highest– lowest). 5. The average age for each age catego
Computers and Technology
1 answer:
schepotkina [342]3 years ago
7 0

Answer:

The solution code is written in Python 3:

  1. count = 0
  2. totalAge = 0
  3. group1_count = 0    #age < 10
  4. group2_count = 0    #age 10 - 20
  5. group3_count = 0    #age 20 - 40
  6. group4_count = 0    #age > 40
  7. group1_total = 0    #subtotal age <= 10
  8. group2_total = 0    #subtotal age 11 - 20  
  9. group3_total = 0    #subtotal age 21 - 40  
  10. group4_total = 0    #subtotal age > 40
  11. age = int(input("Input an age: "))
  12. youngest = age
  13. oldest = age
  14. while(age != -1):
  15.    count += 1
  16.    totalAge += age
  17.    
  18.    if(age <= 10):
  19.        group1_count += 1
  20.        group1_total += age
  21.    elif(age <= 20):
  22.        group2_count += 1
  23.        group2_total += age
  24.    elif(age <= 40):
  25.        group3_count += 1
  26.        group3_total += age
  27.    else:
  28.        group4_count += 1
  29.        group4_total += age
  30.    if(youngest > age):
  31.        youngest = age  
  32.    
  33.    if(oldest < age):
  34.        oldest = age  
  35.    age = int(input("Input an age: "))
  36.    
  37. totalCustomer = count  
  38. avgAge = totalAge / count  
  39. rangeAge = oldest - youngest  
  40. avgAgeGroup1 = group1_total / group1_count  
  41. avgAgeGroup2 = group2_total / group2_count  
  42. avgAgeGroup3 = group3_total / group3_count  
  43. avgAgeGroup4 = group4_total / group4_count  
  44. print("The total number of customers: " + str(totalCustomer))
  45. print("Total number of customer in Group 1 (<=10): " + str(group1_count))
  46. print("Total number of customer in Group 2 (11 - 20): " + str(group2_count))
  47. print("Total number of customer in Group 3 (21 - 40): " + str(group3_count))
  48. print("Total number of customer in Group 4 (> 40): " + str(group4_count))
  49. print("Average age for all customer: " + str(avgAge))
  50. print("Youngest age: " + str(youngest))
  51. print("Oldest age: " + str(oldest))
  52. print("The range of age: " + str(rangeAge))
  53. print("Average age for group 1 (<=10): " + str(avgAgeGroup1))
  54. print("Average age for group 2 (11 - 20): " + str(avgAgeGroup2))
  55. print("Average age for group 3 (21 - 40): " + str(avgAgeGroup3))
  56. print("Average age for group 4 (> 40): " + str(avgAgeGroup4))

Explanation:

Firstly, create the counter variables (e.g. count, group1_count, group2_count etc ) to track the total number of customer and number in each age group. Besides, create variables to hold the value of total of age and sub-total of each age group (Line 1 - 10). We presume there are only four age groups.

Next, prompt user to input the first age (Line 12)

Create variable youngest and oldest to track the lowest and highest age (Line 13 -14). At the moment, set the first input age as value of youngest and oldest.

Create a while loop with sentinel value  -1 (Line 16). Within the loop, track the customer occurrence by incrementing counter variables by one (Line 17, 21, 24, 27 & 30). At the same time, add the current input age to totalAge and to group total (Line 18, 22, 25, 28, & 31).

If the current youngest value is bigger than the current input age, we set the current age to youngest (Line 33- 34).

If the current oldest value is smaller than the current input age, we set the current age to oldest (Line 36- 37).

After terminating the loop with -1, calculate the average age for all customers and for each age group and the range of age (Line 42- 48)  

At last, display all the required calculation results using print function (50 - 62)

You might be interested in
Given the following knowledge representation, what is a simple English sentence that it represents? PTRAN agent=John object=John
Sedaia [141]

Answer:

John is from London and is on a plane to London

Explanation:

The is known as a parallel text alignment or parallel translator.

8 0
3 years ago
In what forms of a graph, DFS and BFS will have same order of explored states ?
agasfer [191]
Is there a picture to go with it
5 0
3 years ago
A printer is displaying no images on its LED panel. What can a technician do to troubleshoot the situation? Choose two answers.
Digiron [165]

Answer:

Explanation:

Check to make sure the printer is plugged in and turned on

8 0
3 years ago
An artificial satellite in which people can live and work for long periods is called a
morpeh [17]
A space station is an artificial satellite in which people can live and work for a long period of time. Space station is placed on the space for the astronaut in researching things on the space and universe.
8 0
3 years ago
Read 2 more answers
2 types of input and output devices that an estate agent requires in their office.
GrogVix [38]
Assuming the estate agent uses a desktop computer they're definitely going to need:

Input: Mouse, Keyboard
Output: Monitor, Printer.

Input devices are those that put data into the computer, while output is the opposite. 
5 0
3 years ago
Other questions:
  • Thelma is a web developer for a bowling league. She wants visitors to the website to be able to print web pages, such as league
    14·1 answer
  • A curb of this color means you may stop only to pick up or drop offs passengers or male
    7·1 answer
  • When a cache block has been modified since being read from main memory?
    10·2 answers
  • chapter tests and exams are password protected and must be taken in the lab with a universal kiosk browser
    12·1 answer
  • Bill downloaded an antivirus software from the Internet. Under the Uniform Commercial Code (UCC), the software is a: Select one:
    15·1 answer
  • Don wishes to swap the values of the variables x and y in his program. He adds a line of code which sets the value of x to the v
    7·1 answer
  • Between Handshake protocol, change cipher suite, alert and appplication data protocols, the first one to use is:
    13·1 answer
  • The advantage of an electronic ____ is that the content can be easily edited and updated to reflect changing financial condition
    10·1 answer
  • Write an algorithm to print the minimum and maximum of an integer array. Your need to pass the array as a parameter. Since we ca
    14·1 answer
  • Should a UDP packet header contain both Sour Port # and Destination Port #?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!