19.8k views
17 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.

User Nicosmik
by
4.3k points

1 Answer

6 votes

Answer:

Step-by-step explanation:

The following code is written in Python. It is a function that takes in a list of ints as a parameter. It then creates two variables one for sum and for max. It then loops through the list adding all the values to sum and adding only the largest value to max. Then it creates a variable called avg which calculates the average by dividing the variable sum by the number of elements in the list. Finally, it returns both avg and max to the user.

def avg_and_max(my_list):

sum = 0

max = 0

for x in my_list:

sum += x

if x > max:

max = x

avg = sum / len(my_list)

return avg, max

User ProfessorDante
by
4.3k points