-
Notifications
You must be signed in to change notification settings - Fork 0
/
who_likes_it.py
39 lines (35 loc) · 1012 Bytes
/
who_likes_it.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
def like(func):
"""
>>> likes([])
'no one likes this'
>>> likes(["Peter"])
'Peter likes this'
>>> likes(["Jacob", "Alex"])
'Jacob and Alex like this'
>>> likes(["Max", "John", "Mark"])
'Max, John and Mark like this'
>>> likes(["Alex", "Jacob", "Mark", "Max"])
'Alex, Jacob and 2 others like this'
"""
def wrapper(*args):
if len(*args) < 2:
return func(*args) + " likes this"
else:
return func(*args) + " like this"
return wrapper
@like
def likes(names: list) -> str:
if names:
if len(names) == 1:
return names[0]
elif len(names) == 2:
return " and ".join(names)
elif len(names) == 3:
return f"{names[0]}, {names[1]} and {names[2]}"
elif len(names) > 3:
return f"{names[0]}, {names[1]} and {len(names)-2} others"
else:
return "no one"
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=True)