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
1numbers = [3, 18, 2, 1, 70, 12, 36, 12, 78, 5, 6, 9]
2
3import statistics
4
5print(statistics.mean(numbers))
1list = [15, 18, 2, 36, 12, 78, 5, 6, 9]
2
3# for older versions of python
4average_method_one = sum(list) / len(list)
5# for python 2 convert len to a float to get float division
6average_method_two = sum(list) / float(len(list))
7
8# round answers using round() or ceil()
9print(average_method_one)
10print(average_method_two)
1
2#python3
3
4def average(list):
5 result = sum(list) / len(list)
6 return result
7
8list = [68,68,71,71,71,75,71,78,91,98,75,71,84]
9print(average(list))
1#!/bin/python3
2
3import math
4import os
5import random
6import re
7import sys
8
9
10# write your code here
11def avg(*n):
12 sumOfNumber = 0
13 for t in n:
14 sumOfNumber = sumOfNumber + t
15 avge = sumOfNumber / len(n)
16 return avge
17if __name__ == '__main__':
18 fptr = open(os.environ['OUTPUT_PATH'], 'w')
19
20 nums = list(map(int, input().split()))
21 res = avg(*nums)
22
23 fptr.write('%.2f' % res + '\n')
24
25 fptr.close()
1# A function that finds an average of a list of numbers
2
3numbers = [1,2,3,4,5,6,7,889,102390143]
4
5def find_average(number_list):
6
7 total = 0
8
9 for number in number_list:
10 total += number
11
12 average = total / len(number_list)
13
14 print("Your average is:", average)
15
16find_average(numbers)