Answers for "fibonacci series in python3"

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

fibonacci series in python

def iterativeFibonacci(n):
  fibList[0,1]
  for i in range(1, n+1):
    fibList.append(fibList[i] + fibList[i-1])
  return fibList[1:]

########################### Output ##################################

""" E.g. if n = 10, the output is --> [1,1,2,3,5,8,13,21,34,55] """
Posted by: Guest on January-14-2021
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
42

fibonacci series in python

first = 1
middle = 1
last =  1
count = 0
n = int(input("Enter how many numbers to be displayed: "))
print(0)
print(first)
print(middle)
while(True):
    last = middle
    middle = first + middle
    first = last
    print(middle)
    count += 1
    if (count == n):
        break
Posted by: Guest on July-20-2021

Python Answers by Framework

Browse Popular Code Answers by Language