-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFibonacci_Sequence_Starting_From_1.py
35 lines (35 loc) · 1.48 KB
/
Fibonacci_Sequence_Starting_From_1.py
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
#Program to find the Fibonacci Sequence starting from 1 to a given position and find the Fibonacci Number at any position upto this given position
def fibonacci_seq_from_one():
n=input('Enter the position upto which you want to find the fibonacci sequence')
N=int(n)
b=input('Enter the position of the fibonacci number you want to find')
B=int(b)
if N==1:
print('The fibonacci sequence upto the first position starting from',1,'is')
elif N==2:
print('The fibonacci sequence upto the second position starting from',1,'is')
elif N==3:
print('The fibonacci sequence upto the third position starting from',1,'is')
else:
print('The fibonacci sequence upto the',N,'th position starting from',1,'is')
lst=[1,2,3]
if N<=3:
print(lst[0:N])
if B==1:
print('First number of the fibonacci sequence is',lst[0])
elif B==2:
print('Second number of the fibonacci sequence is',lst[1])
elif B==3:
print('Third number of the fibonacci sequence is',lst[2])
else:
for i in range(4,N+1):
lst.append(lst[-1]+lst[-2])
print(lst)
if B==1:
print('First number of the fibonacci sequence is',lst[0])
elif B==2:
print('Second number of the fibonacci sequence is',lst[1])
elif B==3:
print('Third number of the fibonacci sequence is',lst[2])
else:
print(B,'th number of fibonacci sequence is',lst[B-1])