Function in Python that determines the Fibonacci number at 'n' index
In mathematics, the Fibonacci numbers form a sequence, the Fibonacci sequence, in which each number is the sum of the two preceding ones.
The sequence commonly starts from 0 and 1, although some authors omit the initial terms and start the sequence from 1 and 1 or from 1 and 2.
Starting from 0 and 1, the next few values in the sequence are:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
# The Fibonacci number present at nth index
def fibo(n):
if n==0:
return 0
elif n==1:
return 1
else:
return fibo(n-1) + fibo(n-2)
n = int(input("Enter the number: "))
print(fibo(n))
Comments
Post a Comment
Write something to CodeWithAbdur!