Skip to content

Commit 3786601

Browse files
authored
Merge pull request prabhupant#77 from Chhaganlaal/master
Nth Fibonacci Number of the Sequence
2 parents 59e4320 + ea803fc commit 3786601

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

algorithms/math/fibonacci_number.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def calc_fib(num):
2+
while len(fib)<=num:
3+
n = len(fib)
4+
fib.append((fib[n-1]+fib[n-2]))
5+
6+
def main():
7+
print("Enter the Position of the Number in the Sequence or \'0\' to Quit: ")
8+
num = 0
9+
fib = list()
10+
fib.append(0)
11+
fib.append(1)
12+
while True:
13+
num = int(input())
14+
if(num<=0):
15+
break
16+
17+
if len(fib)<=num:
18+
calc_fib(num)
19+
20+
print('Fibonacci Number at Position '+str(num)+' is: '+str(fib[num]))
21+
22+
if __name__ == '__main__':
23+
main()

0 commit comments

Comments
 (0)