Skip to content

Commit 9253108

Browse files
Recursion - Febonacci series
1 parent 09e6fd3 commit 9253108

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

febonacci.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def febonacci_without_recurssion(num):
2+
s = [0,1]
3+
for index in range(num):
4+
l = len(s)
5+
prev1 = s[l-1]
6+
prev2 = s[l-2]
7+
s.append(prev1+prev2)
8+
print(s)
9+
10+
11+
def febonacci_with_recussion1 (a,b,sum,num):
12+
if num == 0:
13+
return sum
14+
next = a+b
15+
sum += next
16+
total_sum = febonacci_with_recussion1(b,next,sum, num-1)
17+
return total_sum
18+
19+
def febonacci_with_recussion(a,b,num):
20+
next = a+b
21+
if num == 2:
22+
return a+b
23+
small = febonacci_with_recussion(b,next, num-1)+ a
24+
return small
25+
26+
27+
print(febonacci_with_recussion(0,1,5))

0 commit comments

Comments
 (0)