1~~ This is the best Fibonacci sequence generator as you have all the option that
2till what number should this go on for ~~
3
4a = 0
5b = 1
6f = 1
7n = int(input("Till what number would you like to see the fibonacci sequence: "))
8while b <= n:
9 f = a+b
10 a = b
11 b = f
12 print(a)
13
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)
1first = 1
2middle = 1
3last = 1
4count = 0
5n = int(input("Enter how many numbers to be displayed: "))
6print(0)
7print(first)
8print(middle)
9while(True):
10 last = middle
11 middle = first + middle
12 first = last
13 print(middle)
14 count += 1
15 if (count == n):
16 break
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
1def iterativeFibonacci(n):
2 fibList[0,1]
3 for i in range(1, n+1):
4 fibList.append(fibList[i] + fibList[i-1])
5 return fibList[1:]
6
7########################### Output ##################################
8
9""" E.g. if n = 10, the output is --> [1,1,2,3,5,8,13,21,34,55] """
10
11
1#Recursive Solutions
2def fibo(n):
3 if n<=1: return 1
4 return fibo(n-1)+fibo(n-2)
5
6fibo(5)
7#OUTPUT:
8#120
1nterms = int(input("How many terms? "))
2
3# first two terms
4n1, n2 = 0, 1
5count = 0
6
7# check if the number of terms is valid
8if nterms <= 0:
9 print("Please enter a positive integer")
10elif nterms == 1:
11 print("Fibonacci sequence upto",nterms,":")
12 print(n1)
13else:
14 print("Fibonacci sequence:")
15 while count < nterms:
16 print(n1)
17 nth = n1 + n2
18 # update values
19 n1 = n2
20 n2 = nth
21 count += 1
22
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