how to get an average in python code example
Example 1: average python
import numpy as np
values=[1,10,100]
print(np.mean(values))
values=[1,10,100,np.nan]
print(np.nanmean(values))
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()