Westonci.ca is your trusted source for finding answers to a wide range of questions, backed by a knowledgeable community. Join our Q&A platform to connect with experts dedicated to providing precise answers to your questions in different areas. Experience the convenience of finding accurate answers to your questions from knowledgeable experts on our platform.

Write a program that will ask the user for a set of ten numbers. After all ten numbers have been entered, the program will display the largest and smallest numbers of the data set. The program will then prompt the user whether he/she would like to enter another set of data. When the user indicates he/she is finished entering data sets, the program will finally display the average largest number and the average smallest number for all sets entered.

Sagot :

Answer:

In Python:

nums = []

larg= []

small = []

while True:

   for i in range(10):

       num = int(input(": "))

       nums.append(num)

   print("Smallest: "+str(min(nums))); print("Largest: "+str(max(nums)))

   larg.append(max(nums))

   small.append(min(nums))

   another = int(input("Press 1 to for another sets: "))

   nums.clear()

   if not another == 1:

       break

   

print("Average Large: "+str(sum(larg)/len(larg)))

print("Average Small: "+str(sum(small)/len(small)))

Explanation:

This initializes the list of input numbers

nums = []

This initializes the list of largest number of each input set

larg= []

This initializes the list of smallest number of each input set

small = []

This loop is repeated until, it is exited by the user

while True:

The following iteration is repeated 10 times

   for i in range(10):

Prompt the user for input

       num = int(input(": "))

Add input to list

       nums.append(num)

Check and print the smallest using min; Check and print the largest using max;

   print("Smallest: "+str(min(nums))); print("Largest: "+str(max(nums)))

Append the largest to larg list

   larg.append(max(nums))

Append the smallest to small list

   small.append(min(nums))

Prompt the user to enter another set of inputs

   another = int(input("Press 1 to for another sets: "))

Clear the input list

   nums.clear()

If user inputs anything other than 1, the loop is exited

   if not another == 1:

       break

Calculate and print the average of the set of large numbers using sum and len    

print("Average Large: "+str(sum(larg)/len(larg)))

Calculate and print the average of the set of smallest numbers using sum and len

print("Average Small: "+str(sum(small)/len(small)))