Fibonacci Series
Wed May 25 2022 12:52:08 GMT+0000 (UTC)
Saved by
@redpsych
# Function for nth Fibonacci number
def Fibonacci(n):
# Check if input is 0 then it will
# print incorrect input
if n < 0:
print("Incorrect input")
# Check if n is 0
# then it will return 0
elif n == 0:
return 0
# Check if n is 1,2
# it will return 1
elif n == 1 or n == 2:
return 1
else:
return Fibonacci(n-1) + Fibonacci(n-2)
# Driver Program
print(Fibonacci(9))
# This code is contributed by Saket Modi
# then corrected and improved by Himanshu Kanojiya
content_copyCOPY
https://www.geeksforgeeks.org/python-program-for-program-for-fibonacci-numbers-2/?ref=lbp
Comments