Skip to content

Commit 974110f

Browse files
bhansat2013anurag
authored andcommitted
added fibonnaci recursion example (hacktoberfest17#972)
1 parent 0ae0092 commit 974110f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def fibo(n):
2+
# if n is 1 return 1
3+
if n == 1:
4+
return 1
5+
# if n is 2 still return 1
6+
elif n == 2:
7+
return 1
8+
# else return the sum of last to terms
9+
elif n > 2:
10+
return fibo(n-1) + fibo(n-2)
11+
12+
# for loop for sum fibonacci numbers upto n
13+
for i in range(1, 10):
14+
# printing fibonacci numbers according to term number
15+
print(i, ":", fibo(i))

0 commit comments

Comments
 (0)