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
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# 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)