208k views
1 vote
LAB: Varied amount of input data

Statistics are often calculated with varying amounts of input data. Write a program that takes any number of integers as input, and outputs the average and max.
Ex: If the input is:
15 20 0 5
the output is:
10 20

User Jkovba
by
5.2k points

2 Answers

3 votes

Final answer:

To write a program that takes any number of integers as input and outputs the average and max, you can use a loop to continuously take input from the user until they indicate they're done entering numbers. After the loop, you can calculate the average by dividing the sum by the total number of integers entered.

Step-by-step explanation:

To write a program that takes any number of integers as input and outputs the average and max, you can use a loop to continuously take input from the user until they indicate they're done entering numbers. Within the loop, you can keep track of the sum of the numbers entered and the maximum number so far. After the loop, you can calculate the average by dividing the sum by the total number of integers entered. Here's an example program in Python:

sum = 0max_number = float('-inf')count = 0

while True:
num = input('Enter an integer (or done to finish): ')

if num == 'done':
break

num = int(num)
sum += num
count += 1

if num > max_number:
max_number = num

average = sum / count

print('Average:', average)print('Max:', max_number)

User Farawin
by
5.6k points
3 votes

Answer:

Answered below

Step-by-step explanation:

#python program

#First get the number of inputs from user

num_inputs = int(input("Enter number of inputs:")

j = 0

sum =0

max = 0

while j < num_inputs:

num = int(input ("Enter numbers: ")

sum = sum + num

if num > max:

max = num

j++

#Compute the average

average = sum/num_inputs

print (average, max)

User Marti
by
4.9k points