Q:

how to calculate the average of a list in python

# Example to find average of list
number_list = [45, 34, 10, 36, 12, 6, 80]
avg = sum(number_list)/len(number_list)
print("The average is ", round(avg,2))
5
# Python program to get average of a list 
# Using mean() 
  
# importing mean() 
from statistics import mean 
  
def Average(lst): 
    return mean(lst) 
  
# Driver Code 
lst = [15, 9, 55, 41, 35, 20, 62, 49] 
average = Average(lst) 
  
# Printing average of the list 
print("Average of the list =", round(average, 2)) 
1
# app.py

def averageOfList(num):
    sumOfNumbers = 0
    for t in num:
        sumOfNumbers = sumOfNumbers + t

    avg = sumOfNumbers / len(num)
    return avg


print("The average of List is", averageOfList([19, 21, 46, 11, 18]))
0

New to Communities?

Join the community