Skip to content

Commit e2a1efc

Browse files
realDuYuanChaogithub-actions
andauthored
Add sum (#24)
* sum to n recursion * add sum_big_numbers * Formatted with psf/black Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 8b244c0 commit e2a1efc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

maths/sum_big_numbers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def sum_big_numbers(first_number: int, second_number: int):
2+
"""
3+
>>> sum_big_numbers(1234567891011121314151617181920, 2019181716151413121110987654321)
4+
3253749607162534435262604836241
5+
"""
6+
return first_number + second_number
7+
8+
9+
if __name__ == "__main__":
10+
from doctest import testmod
11+
12+
testmod()

maths/sum_to_n_recursion.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def sum_to_n_recursion(number: int) -> int:
2+
"""
3+
>>> sum_to_n_recursion(0)
4+
0
5+
>>> sum_to_n_recursion(10)
6+
55
7+
>>> sum_to_n_recursion(100)
8+
5050
9+
"""
10+
return 0 if number == 0 else number + sum_to_n_recursion(number - 1)
11+
12+
13+
if __name__ == "__main__":
14+
from doctest import testmod
15+
16+
testmod()

0 commit comments

Comments
 (0)