Calculate the Average in Python Programming

 Python Program to Calculate the Average of Numbers in a Given List. The program takes the elements of the list one by one and displays the average of the elements of the list. Take the number of elements to be stored in the list as input. Use a for loop to input elements into the list. Calculate the total sum of elements in the list. Divide the sum by total number of elements in the list.

INPUT:                                                     

Number of elements to be inserted in list

Values for n numbers

 

OUTPUT:

Average of elements in the list with two decimal places

case=1

input=3

23

45

56

output=41.33

case=2

input=5

12

24

33

25

18

output=22.40


Source Code:

n=int(input())

a=[]

for i in range(0,n):

   elem=int(input())

   a.append(elem)

avg=sum(a)/n

print("Average of element in the list:",round(avg,2))

OUTPUT:

3

23

45

56

Average of element in the list: 41.33






Try it Yourself ( our new feature )

Click on the "Try it Yourself" button to see how it works.



Blog

Post a Comment

Previous Post Next Post