avg of a list python code example
Example 1: average value of list elements in python
number_list = [45, 34, 10, 36, 12, 6, 80]
avg = sum(number_list)/len(number_list)
print("The average is ", round(avg,2))
Example 2: python average function program
import math
import os
import random
import re
import sys
def avg(*n):
sumOfNumber = 0
for t in n:
sumOfNumber = sumOfNumber + t
avge = sumOfNumber / len(n)
return avge
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nums = list(map(int, input().split()))
res = avg(*nums)
fptr.write('%.2f' % res + '\n')
fptr.close()