1# Example to find average of list
2number_list = [45, 34, 10, 36, 12, 6, 80]
3avg = sum(number_list)/len(number_list)
4print("The average is ", round(avg,2))
5
1def avrg(values): # where values is a list of all values
2 return sum(values)/len(values)
1my_list = [1,2,3,4]
2
3import numpy as np
4print("mean = ", np.mean(my_list))
1# app.py
2
3def averageOfList(num):
4 sumOfNumbers = 0
5 for t in num:
6 sumOfNumbers = sumOfNumbers + t
7
8 avg = sumOfNumbers / len(num)
9 return avg
10
11
12print("The average of List is", averageOfList([19, 21, 46, 11, 18]))
1import numpy as np
2values=[1,10,100]
3print(np.mean(values))
4values=[1,10,100,np.nan]
5print(np.nanmean(values))
1def cal_average(num):
2 sum_num = 0
3 for t in num:
4 sum_num = sum_num + t
5
6 avg = sum_num / len(num)
7 return avg
8
9print("The average is", cal_average([18,25,3,41,5]))
10