-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverages.py
73 lines (44 loc) · 1.66 KB
/
averages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import math
def self_averages(grades):
'''(list of list of number) -> list of float
Return a new list in which each item is the average of the grades in the inner list at the corresponding position of grades.
>>> slef_averages([[70,75,80],[70,80,90,100],[80,100]])
[75.0, 85.0, 90.0]
'''
averages = []
for i in range(len(grades)):
averages.append(0)
for j in range(len(grades[i])):
averages[i]= averages[i] + grades[i][j]
averages[i]= averages[i]/len(grades[i])
return averages
def averages(grades):
'''(list of list of number) -> list of float
Return a new list in which each item is the average of the grades in the inner list at the corresponding position of grades.
>>> averages([[70,75,80],[70,80,90,100],[80,100]])
[75.0, 85.0, 90.0]
'''
class_averages = []
for grades_list in grades:
total = 0
for j in grades_list:
total = total + j
class_averages.append(total/len(grades_list))
return class_averages
def standard_deviation(grades):
'''(list of list of number) -> list of float
Return a new list in which each item is the standard deviation of the grades in the inner list at the corresponding position of grades.
>>> grades = [[70,75,80],[70,80,90,100],[80,100]]
>>> a= averages(grades)
>>> a
[5.0, 15.811388300841896, 10.0]
'''
std = []
mean = averages(grades)
for i in range(len(grades)):
total = 0
for j in grades[i]:
total = total + pow(j-mean[i],2)
total = total/(len(grades)-1)
std.append(pow(total,0.5))
return std