forked from An4ik/Python-TDD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_max.py
74 lines (56 loc) · 1.54 KB
/
find_max.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
74
def get_max(a, b):
"""
return max number among a and b
"""
return a if a > b else b
def get_max_without_arguments():
"""
raise TypeError exception with message
"""
raise TypeError('there is no arguments in your function')
def get_max_with_one_argument(a):
"""
return that value
"""
return a
def get_max_with_many_arguments(*args):
"""
return biggest number among args
"""
maxValue = args[0]
for i in args:
if i > maxValue:
maxValue = i
return maxValue
def get_max_with_one_or_more_arguments(first, *args):
"""
return biggest number among first + args
"""
maxValue = first
for i in args:
if i > maxValue:
maxValue = i
return maxValue
def get_max_bounded(*args, low, high):
"""
return biggest number among args bounded by low & high
"""
maxValue = low
for i in args:
if i > low and i < high and i > maxValue:
maxValue = i
return maxValue
def make_max(*, low, high):
"""
return inner function object which takes at least one argument
and return biggest number amount it's arguments, but if the
biggest number is bigger than the 'high' which given as required
argument the inner function has to return it.
"""
def inner(first, *args):
maxValue = low
for i in (first,) + args:
if i > maxValue and low < i < high:
maxValue = i
return maxValue
return inner