S
Seoffix.com
Sign In Get Pro Membership

DSA & Problem Solving

Recursion

Intermediate Python 35 XP

Recursion

A recursive function needs a base case that stops and a step that moves closer to it.

Example

def countdown(n):
    if n == 0:
        return
    countdown(n - 1)

Your task

Write factorial(n) recursively and print factorial(5).

Hints

  1. Stop when n <= 1
  2. Return n * factorial(n - 1)

Check your understanding

Answer every question to pass.
1. What stops a recursive function?

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 35 XP after you pass the quiz. Finish every lesson in the track to earn its certificate.
Sign in to earn XP

DSA & Problem Solving

Lessons in this track
Questions about this lesson? Ask the Coding & Web Dev squad. Discuss in Community