Answers for "python find nth fibonacci number using for loop"

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
1

python fibonacci get nth element

# Dynamic approach to get nth fibonacci number
arr = [0,1]

def fibonacci(n):
   if n<0:
      print("Fibbonacci can't be computed")
   elif n<=len(arr):
      return arr[n-1]
   else:
      temp = fibonacci(n-1)+fibonacci(n-2)
      arr.append(temp)
      return temp

print(fibonacci(9))
Posted by: Guest on October-13-2020

Code answers related to "python find nth fibonacci number using for loop"

Python Answers by Framework

Browse Popular Code Answers by Language