1#Python program to generate Fibonacci series until 'n' value
2n = int(input("Enter the value of 'n': "))
3a = 0
4b = 1
5sum = 0
6count = 1
7print("Fibonacci Series: ", end = " ")
8while(count <= n):
9 print(sum, end = " ")
10 count += 1
11 a = b
12 b = sum
13 sum = a + b
14
1#Recursive fibonnaci series
2def fib(n,arr):
3 if n == 0 or n == 1:
4 return 1
5 else:
6 arr.append(fib(n-1,arr) + fib(n-2,arr))
7 return fib(n-1,arr) + fib(n-2,arr)
8
9n = 10
10arr = [1, 1]
11print(fib(n-1,arr))
12bl = set(arr)
13bb = list(bl)
14bb.sort()
15print([1] + bb)
1# WARNING: this program assumes the
2# fibonacci sequence starts at 1
3def fib(num):
4 """return the number at index num in the fibonacci sequence"""
5 if num <= 2:
6 return 1
7 return fib(num - 1) + fib(num - 2)
8
9
10print(fib(6)) # 8
1Fibonacci_input = int(input("Need Terms please give it: "))
2num1 =0
3num2 = 1
4count = 0
5go_india = True
6while go_india:
7
8 if Fibonacci_input <= 0:
9 print("Please enter a positive integer")
10 elif Fibonacci_input == 1:
11 print("Fibonacci sequence is more than",Fibonacci_input,":")
12 print(num1)
13 elif Fibonacci_input > 1:
14 print("Fibonacci sequence:")
15 while count < Fibonacci_input:
16 print(num1)
17 nth = num1 + num2
18
19 num1 = num2
20 num2 = nth
21 count += 1
22 else:
23 print('incorrect input')
24
25 User_think = input('Do you want to cotinue? write "1 or one" if you want to continue or "2 or two" to exit: ').upper()
26 if User_think == 1 or "ONE":
27 User_think == True
28 elif User_think == 2 or 'TWO':
29 go_india == False
30
31 print('thanks for using me')
32 else:
33 print('wront input closing the software')
34 go_india == False
35
1# Program to display the Fibonacci sequence up to n-th term
2
3nterms = int(input("How many terms? "))
4
5# first two terms
6n1, n2 = 0, 1
7count = 0
8
9# check if the number of terms is valid
10if nterms <= 0:
11 print("Please enter a positive integer")
12elif nterms == 1:
13 print("Fibonacci sequence upto",nterms,":")
14 print(n1)
15else:
16 print("Fibonacci sequence:")
17 while count < nterms:
18 print(n1)
19 nth = n1 + n2
20 # update values
21 n1 = n2
22 n2 = nth
23 count += 1
1#Learnprogramo
2Number = int(input("How many terms? "))
3# first two terms
4First_Value, Second_Value = 0, 1
5i = 0
6if Number <= 0:
7print("Please enter a positive integer")
8elif Number == 1:
9print("Fibonacci sequence upto",Number,":")
10print(First_Value)
11else:
12print("Fibonacci sequence:")
13while i < Number:
14print(First_Value)
15Next = First_Value + Second_Value
16# update values
17First_Value = Second_Value
18Second_Value = Next
19i += 1