Python Program to Calculate the Average of Numbers in a Given List
Python Program to Calculate the Average of Numbers in a Given List
Problem Description
The program takes the elements of the list one by one and displays the average of the elements of the list.
Program/Source Code
Here is source code of the Python Program to Calculate the Average of Numbers in a Given List. The program output is also shown below.
n=int(input("Enter the number of elements to be inserted: "))
a=[]
for i in range(0,n):
elem=int(input("Enter element: "))
a.append(elem)
avg=sum(a)/n
print("Average of elements in the list",round(avg,2))
Runtime Test Cases
Case 1:
Enter the number of elements to be inserted: 3
Enter element: 23
Enter element: 45
Enter element: 56
Average of elements in the list 41.33
Case 2:
Enter the number of elements to be inserted: 5
Enter element: 12
Enter element: 24
Enter element: 33
Enter element: 25
Enter element: 18
Average of elements in the list 22.4