Part of the series

Several example codes

~1 min read • Updated Oct 12, 2025

Program Overview

This Python program uses a recursive method named l1 to display all numbers less than n that are divisible by 3.
The recursion starts from n-1 and checks each number downward.


Python Code:


def l1(n: int):
    if n <= 0:
        return
    if n % 3 == 0:
        print(n)
    l1(n - 1)

# Read input from user
n = int(input("Enter value for n: "))
print(f"Multiples of 3 less than {n}:")
l1(n - 1)

Sample Output (input: n = 11):


Multiples of 3 less than 11:
9  
6  
3

Written & researched by Dr. Shahin Siami