Jun-24-2020, 08:45 AM
(This post was last modified: Jun-24-2020, 08:47 AM by Ayman_2001.)
Greetings,
I've been doing this course on Udacity called CS101 it's quite a effective and challenging one and so far i've enjoyed it quite a lot. But recursive functions are coming that easy to me as I find it somewhat confusing.Thus, if someone can elaborately explain me this function, it would be extremely helpful to me. Thank you!
# Function for nth Fibonacci number
How does it loop without any looping statements?
I've been doing this course on Udacity called CS101 it's quite a effective and challenging one and so far i've enjoyed it quite a lot. But recursive functions are coming that easy to me as I find it somewhat confusing.Thus, if someone can elaborately explain me this function, it would be extremely helpful to me. Thank you!
# Function for nth Fibonacci number
def Fibonacci(n): if n<0: print("Incorrect input") # First Fibonacci number is 0 elif n==0: return 0 # Second Fibonacci number is 1 elif n==1: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2) # Driver Program print(Fibonacci(5)) #This code is contributed by Saket Modi
How does it loop without any looping statements?