Answers for "fibonacci series code 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
2

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)


print(fib(6))  # 8
Posted by: Guest on April-10-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
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

code fibonacci python

# Program to display the Fibonacci sequence forever

def fibonacci(i,j):
  print(i;fibonacci(j,i+j))
fibonacci(1,1)
Posted by: Guest on November-09-2020
5

fibonacci series in python

# Program to display the Fibonacci sequence up to n-th term

nterms = int(input("How many terms? "))

# first two terms
n1, n2 = 0, 1
count = 0

# check if the number of terms is valid
if nterms <= 0:
   print("Please enter a positive integer")
elif nterms == 1:
   print("Fibonacci sequence upto",nterms,":")
   print(n1)
else:
   print("Fibonacci sequence:")
   while count < nterms:
       print(n1)
       nth = n1 + n2
       # update values
       n1 = n2
       n2 = nth
       count += 1
Posted by: Guest on May-12-2020

Code answers related to "fibonacci series code in python"

Python Answers by Framework

Browse Popular Code Answers by Language