Skip to content

Commit 5c111bb

Browse files
authored
Merge pull request #3 from PoApper/feat/minmax-answer
Add an answer for minmax problem
2 parents 1a3e330 + 5908555 commit 5c111bb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

04-functions-modules/minmax-answer.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import random
2+
3+
def myMin(iterable):
4+
"""
5+
>>> myMin([7, 6, 5])
6+
5
7+
>>> myMin([3, 2, 5, 7, 8, 90, 5])
8+
2
9+
>>> sample = [i for i in range(100)]; \
10+
random.shuffle(sample); \
11+
myMin(sample)
12+
0
13+
"""
14+
min_value = iterable[0]
15+
for val in iterable:
16+
if min_value > val:
17+
min_value = val
18+
return min_value
19+
20+
def myMax(iterable):
21+
"""
22+
>>> myMax([7, 6, 5])
23+
7
24+
>>> myMax([3, 2, 5, 7, 8, 90, 5])
25+
90
26+
>>> sample = [i for i in range(100)]; \
27+
random.shuffle(sample); \
28+
myMax(sample)
29+
99
30+
"""
31+
max_value = iterable[0]
32+
for val in iterable:
33+
if max_value < val:
34+
max_value = val
35+
return max_value
36+
37+
if __name__ == "__main__":
38+
import doctest
39+
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)