Average of n numbers from the list using function





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


CODE:

def average(n):
n=int(input("Enter the length of elements :"))
l=[]
for i in range(n):
elem=int(input("Enter the Input numbers:"))
l.append(elem)
average=sum(l)/n
print(round(average,2))
return 1
l=[]
average(1)

OUTPUT:







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