Calculating the arithmetic mean

Report a typo

Write a program that calculates the arithmetic mean. The arithmetic mean is the sum of all numbers divided by their total count.

  • Read an integer n. This number tells you how many numbers you need to read next in a loop.

  • Read exactly n integers, one per line, and calculate the arithmetic mean value of those integers.

  • Print the mean as a float value.

In the examples below, you can see the input format: the first number shows how many times you need to read next in a loop (8, 3, and 1, respectively). The following integers represent numbers whose mean value you should calculate.

You can:

  • Store the first number (n) in a variable.

  • Call input() inside a for loop exactly n times.

Sample Input 1:

8
5
-7
6
2
5
5
-7
-10

Sample Output 1:

-0.125

Sample Input 2:

3
10
20
30

Sample Output 2:

20.0

Sample Input 3:

1
7

Sample Output 3:

7.0
Write a program in Python 3





Create a free account to access the full topic