Easy Guide to Python Recursion
-
I like this page for teaching basic recursion using Python 3.
http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python_3/Recursion
-
The most common sample of recursion is always doing factorials, of course. So here it is in Python.
def main(): num = int(input("Please enter a non-negative integer.\n")) fact = factorial(num) print("The factorial of", num, "is", fact) def factorial(num): if num == 0: return 1 else: return num * factorial(num - 1) main()