-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_3.py
45 lines (30 loc) · 1.08 KB
/
task_3.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
# Home Work Solutions 3
"""
Write a function some_sum with the following behavior:
# def some_sum
some_summ(1) #-> 1
some_summ(1) + some_summ(1) #-> 2
some_summ(1, 2, 3) #-> 6
some_summ(1)(2) #-> 3
some_summ(1)(2)(1, 2, 3) #-> 9
some_summ(1)(2)(1, 2, 3) + some_summ(1)(2) #-> 12
some_summ(1)(2)(1, 2, 3)(1) #-> 10
some_summ(1)()() #-> 1
some_summ(1)()(1) * some_summ(1)(2)() #-> 4 Тут ошибка! Результат выражения == 6!
"""
class MyClass(int):
def __call__(self, *argv):
return some_sum(self, *argv)
def some_sum(*args):
res = sum(args)
return MyClass(res)
if __name__ == '__main__':
assert some_sum(1) == 1
assert some_sum(1) + some_sum(1) == 2
assert some_sum(1, 2, 3) == 6
assert some_sum(1)(2) == 3
assert some_sum(1)(2)(1, 2, 3) == 9
assert some_sum(1)(2)(1, 2, 3) + some_sum(1)(2) == 12
assert some_sum(1)(2)(1, 2, 3)(1) == 10
assert some_sum(1)()() == 1
assert some_sum(1)()(1) * some_sum(1)(2)() == 4 # Ошибка в условии. Результат должен быть 2 + 3 == 6, а не 4.