Wednesday, June 26, 2019

Python Program | Calculate the Average of Numbers in a List

Problem

The program takes the elements of the list one by one and displays the average of the elements of the list. This is a Python Program to Calculate the Average of Numbers in a Given List.

Program/Source Code

Here is source code of the Python Program to Calculate the Average of Numbers in a List. The program output is also shown below.
 
num=int(input("Enter the number of elements: "))
arr=[]
for i in range(0,num):
    element=int(input("Enter element one by one: "))
    arr.append(element)
avg=sum(arr)/num
print("Average of elements in the list",round(avg,2))

Test Cases

 
Test 1:
Enter the number of elements: 3
Enter element one by one: 23
Enter element one by one: 45
Enter element one by one: 56
Average of elements in the list 41.33
 
Test 2:
Enter the number of elements: 5
Enter element one by one: 12
Enter element one by one: 24
Enter element one by one: 33
Enter element one by one: 25
Enter element one by one: 18
Average of elements in the list 22.4
If You Enjoyed This, Take 5 Seconds To Share It