Skip to content

Commit 1a3e330

Browse files
authored
min max test (#1)
* implt minmax test * fix return * feedback
1 parent 2104d81 commit 1a3e330

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

04-functions-modules/guide.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
# functions and modules
1+
# functions and modules
2+
3+
## MinMax
4+
- difficulty: ★☆☆
5+
- time: ~ 15m for beginners
6+
- background: list, iteration
7+
8+
Implement `min`, `max` functions on your own.

04-functions-modules/minmax.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
# TODO
15+
16+
def myMax(iterable):
17+
"""
18+
>>> myMax([7, 6, 5])
19+
7
20+
>>> myMax([3, 2, 5, 7, 8, 90, 5])
21+
90
22+
>>> sample = [i for i in range(100)]; \
23+
random.shuffle(sample); \
24+
myMax(sample)
25+
99
26+
"""
27+
# TODO
28+
29+
if __name__ == "__main__":
30+
import doctest
31+
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)