Python Program to Calculate Average of Numbers in a List
Write a python program to calculate average of n numbers in a list.
In this program, we are going to accept the size of list, accept n
numbers and calculate the average by traversing the list using for loop.
Finally we are printing the average.
Run-time Platform: GCC 9.2
Programming Language: C
Source Code Type: Full (Compile Ready) Solution
Python program to calculate average of n numbers in a given list
num=int(input("Enter the number of elements to be inserted into List: "))
list1=[]
# accept list numbers
for i in range(0,num):
ele=int(input("Enter any integer: "))
list1.append(ele)
# store average
avg=sum(list1)/num
# print average
print("Average of elements in the list",round(avg,2))
Output:
Enter the number of elements to be inserted into List: 5 Enter any integer: 10 Enter any integer: 20 Enter any integer: 30 Enter any integer: 40 Enter any integer: 50 Average of elements in the list 30.0
Comments