Easy Guide to Python Recursion
scottalanmiller last edited by scottalanmiller
I like this page for teaching basic recursion using Python 3.
scottalanmiller last edited by
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()