86.3k views
4 votes
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 Note: For output, round the average to the nearest integer.

User Thrastylon
by
8.8k points

1 Answer

3 votes

Answer:

txt = input("Enter numbers: ")

numbers = txt.split(" ")

total = 0

max = 0

for i in numbers:

total = total + int(i)

if(int(i)>max):

max = int(i)

print(round(total/len(numbers)))

print(max)

Step-by-step explanation:

This solution is implemented using Python programming language

This prompts user for input

txt = input("Enter numbers: ")

This splits user input into list

numbers = txt.split(" ")

The next two line initialize total and max to 0, respectively

total = 0

max = 0

This iterates through the list

for i in numbers:

This sum up the items in the list (i.e. user inputs)

total = total + int(i)

This checks for the maximum

if(int(i)>max):

max = int(i)

This calculates and prints the average

print(round(total/len(numbers)))

This prints the max

print(max)

User Dariusz Mydlarz
by
8.2k points