Part of the series

Several example codes

~1 min read • Updated Oct 11, 2025

Program Overview

This Python program reads a number from the user and performs a countdown from that number to 1 using recursion.
Each step prints the current number until it reaches 1.
This exercise is ideal for practicing recursive function design and base-case logic.


Python Code:


def recursive_countdown(n):
    if n < 1:
        return
    print(n)
    recursive_countdown(n - 1)

# Run the program
number = int(input("Enter a number to start countdown: "))
recursive_countdown(number)

Sample Output (input: 5):


5
4
3
2
1

Step-by-Step Explanation:

- The program reads a number from the user
- It calls the recursive_countdown function with that number
- The function prints the number, then calls itself with n - 1
- The recursion stops when n becomes less than 1
- The result is a clean countdown from the input number to 1


Written & researched by Dr. Shahin Siami