-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path05_Recursion_Function.py
More file actions
44 lines (36 loc) · 919 Bytes
/
05_Recursion_Function.py
File metadata and controls
44 lines (36 loc) · 919 Bytes
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
def getFibonacci(position):
"""
Fibonacci Series
0, 1, 1, 2, 3, 5, 8, 13......
Example:
position = 6
return = 8
"""
if (position == 0):
return 0
if (position == 1):
return 1
first = 0
second = 1
nextt = first + second
for _ in range(2, position):
first = second;
second = nextt;
nextt = first + second;
return nextt
def getFibonacciRecursion(position):
"""
Fibonacci Series
0, 1, 1, 2, 3, 5, 8, 13......
Example:
position = 6
return = 8
"""
if position == 0 or position == 1:
return position
return getFibonacciRecursion(position - 1) + getFibonacciRecursion(position - 2)
position = int(input())
for i in range(position):
#Note - Comment one of them
print(getFibonacci(i), end=" ")
# print(getFibonacciRecursion(i), end=" ")