LearnFrenzy
Sign in Take a free test

Recursion · Predict the Output · Question 2

A recursive countdown Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What is the output of the following Python program?

main.py
def countdown(n):
    if n == 0:
        print("Go!")
        return
    print(n)
    countdown(n - 1)

countdown(3)
  • A 1 2 3 Go!
  • B Go! 1 2 3
  • C 3 2 1 Go! Correct
  • D 3 2 1 0 Go!
Correct Answer: Option C

Each call prints before recursing, so numbers appear in calling order, then the base case prints Go!.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links