-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_test_functions.py
More file actions
58 lines (46 loc) · 1.15 KB
/
Copy pathsimple_test_functions.py
File metadata and controls
58 lines (46 loc) · 1.15 KB
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
#!/usr/bin/env python3
""" A few simple functions """
def max_of_three_bad(x, y, z):
""" (int, int, int) -> int
Attempts to determine and return the maximum of three
numeric values
"""
result = x
if y > result:
result = y
elif z > result:
result = z
return result
def max_of_three_good(x, y, z):
""" (int, int, int) -> int
Computes and returns the maximum of three numeric values
"""
result = x
if y > result:
result = y
if z > result:
result = z
return result
def sum_up(lst):
""" (list) -> int
Attempts to compute and return the sum of all the elements in a list
of integers
"""
total = 0
for i in range(1, len(lst)):
total += lst[i]
return total
def maximum(lst):
"""(list) -> int
Computes the maximum element in a list of integers
"""
return 0 # Not implemented
class ListManager(object):
def __init__(self, lst):
super().__init__()
self.lst = lst
def get(self, idx):
"""
Return list item at index idx
"""
return self.lst[idx] # Subject to range exception