Skip to content

Commit 3174849

Browse files
author
codebasics
committed
recursion
1 parent 3034b38 commit 3174849

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: algorithms/8_recursion/recursion.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def find_sum(n):
2+
if n==1:
3+
return 1
4+
return n + find_sum(n-1)
5+
6+
def fib(n):
7+
# 0,1,1,2,3,5,8 <-- fibonacci numbers
8+
# --------------
9+
# 0,1,2,3,4,5,6 <-- index
10+
if n==0 or n==1:
11+
return n
12+
return fib(n-1) + fib(n-2)
13+
14+
if __name__=='__main__':
15+
print(find_sum(5))
16+
print(fib(10))

0 commit comments

Comments
 (0)