Answers for "print fibonacci series in python"

5

how to create fibonacci sequence in python

#Python program to generate Fibonacci series until 'n' value
n = int(input("Enter the value of 'n': "))
a = 0
b = 1
sum = 0
count = 1
print("Fibonacci Series: ", end = " ")
while(count <= n):
  print(sum, end = " ")
  count += 1
  a = b
  b = sum
  sum = a + b
Posted by: Guest on May-21-2020
10

fibonacci sequence python

# WARNING: this program assumes the
# fibonacci sequence starts at 1
def fib(num):
	"""return the number at index `num` in the fibonacci sequence"""
    if num <= 2:
        return 1
    return fib(num - 1) + fib(num - 2)

# method 2: use `for` loop
def fib2(num):
	a, b = 1, 1
	for _ in range(num - 1):
		a, b = b, a + b
	return a


print(fib(6))  # 8
print(fib2(6))  # same result, but much faster
Posted by: Guest on February-24-2020
2

fibonacci series in python

~~ This is the best Fibonacci sequence generator as you have all the option that 
till what number should this go on for ~~
  
a = 0
b = 1
f = 1
n = int(input("Till what number would you like to see the fibonacci sequence: "))
while b <= n:
    f = a+b
    a = b
    b = f
    print(a)
Posted by: Guest on January-22-2021
1

fibonacci series in python

#Recursive fibonnaci series
def fib(n,arr):
    if n == 0 or n == 1:
        return 1 
    else:
        arr.append(fib(n-1,arr) + fib(n-2,arr))
        return fib(n-1,arr) + fib(n-2,arr)
        
n = 10
arr = [1, 1]
print(fib(n-1,arr))
bl = set(arr)
bb = list(bl)
bb.sort()
print([1] + bb)
Posted by: Guest on September-09-2021
0

fibonacci series in python

#Recursive Solutions
def fibo(n):
  if n<=1: return 1
  return fibo(n-1)+fibo(n-2)

fibo(5)
#OUTPUT:
#120
Posted by: Guest on September-29-2020
1

fibonacci series in python

Fibonacci_input = int(input("Need Terms please give it: "))
num1 =0
num2 = 1
count = 0
go_india = True
while go_india:
   
   if Fibonacci_input <= 0:
      print("Please enter a positive integer")
   elif Fibonacci_input == 1:
      print("Fibonacci sequence is more than",Fibonacci_input,":")
      print(num1)
   elif Fibonacci_input > 1:
      print("Fibonacci sequence:")
      while count < Fibonacci_input:
         print(num1)
         nth = num1 + num2
      
         num1 = num2
         num2 = nth
         count += 1
   else:
      print('incorrect input')
   
   User_think = input('Do you want to cotinue? write "1 or one" if you want to continue or "2 or two" to exit: ').upper()
   if User_think == 1 or "ONE":
         User_think == True
   elif User_think == 2 or 'TWO':
      go_india == False
      
      print('thanks for using me')
   else:
      print('wront input closing the software')
      go_india == False
Posted by: Guest on June-23-2021

Code answers related to "print fibonacci series in python"

Python Answers by Framework

Browse Popular Code Answers by Language