Python Forum
Python recursive functions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python recursive functions
#1
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
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?
Reply


Messages In This Thread
Python recursive functions - by Ayman_2001 - Jun-24-2020, 08:45 AM
RE: Python recursive functions - by ndc85430 - Jun-24-2020, 10:14 AM
RE: Python recursive functions - by jefsummers - Jun-24-2020, 11:32 AM
RE: Python recursive functions - by Ayman_2001 - Jun-24-2020, 01:23 PM
RE: Python recursive functions - by deanhystad - Jun-24-2020, 02:11 PM
RE: Python recursive functions - by jefsummers - Jun-24-2020, 05:40 PM
RE: Python recursive functions - by ndc85430 - Jun-24-2020, 07:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Recursive functions Ayman_2001 3 2,174 Jun-27-2020, 03:46 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020