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~~ 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
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
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
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