forked from RSE-102/automation-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operations.py
64 lines (47 loc) · 1.14 KB
/
operations.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
"""
A set of mathematical operations.
"""
def find_max(data):
"""
Find maximum of all elements of a given list
Parameters
----------
data : list
List of data. Elements are numbers
Returns
-------
find_max : float
Maximum of list
"""
# Check that the input list has numbers
for n in data:
assert type(n) == int or type(n) == float
max_num = data[0] # Assume the first number is the maximum
for n in data:
if n > max_num:
max_num = n
return max_num
def find_mean(data):
"""
Find mean of all elements of a given list
Parameters
----------
data : list
List of data. Elements are numbers
Returns
-------
float : float
Mean of list
"""
# Check that the input list has numbers
for n in data:
assert type(n) == int or type(n) == float
return sum(data) / len(data)
def main():
data = [5, 3, 14, 27, 4, 9]
maximum = find_max(data)
print("Maximum = {}".format(maximum))
mean = find_mean(data)
print("Average = {}".format(mean))
if __name__ == "__main__":
main()