how to take average of an array in python code example

Example 1: python average

# Using statistics package to find average
import statistics as st

my_list = [9, 3, 1, 5, 88, 22, 99]
print(st.mean(my_list))

Example 2: python average function program

#!/bin/python3

import math
import os
import random
import re
import sys


# write your code here
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()