Founding Batch Offer · HLD · LLD · System Design at ₹799 until 30 Nov

Multiplication Table Recursively

Print a ten-row multiplication table through recursion. Students increment a multiplier argument and stop after ten while keeping the entered base unchanged.

IntermediatePhase 3 - Level 3: Pattern RecursionExample 7 of 10
multiplication-table-recursively.py
1def print_table_row(n, multiplier=1):
2 # Base case
3 if multiplier > 10:
4 return
5
6 # Print current row
7 print(f"{n} × {multiplier} = {n * multiplier}")
8 # Recurse
9 print_table_row(n, multiplier + 1)
10
11# Test
12n = int(input("Enter number: "))
13print_table_row(n)

Output

...

The sample abbreviates a longer result. The program prints the intervening values; it does not print these dots.

In this one

  • Advance a multiplier
  • Keep the table base fixed
  • Use a fixed-depth recursion

How it works

  1. 1

    Return when multiplier exceeds ten.

  2. 2

    Print n times the current multiplier.

  3. 3

    Request the next multiplier with n unchanged.

Edge cases

Does n = 0 work?

Does n = 0 work?

Yes. It prints ten zero products.

Can n be negative?

Can n be negative?

Yes. The multiplier still advances to eleven.

What's going on

The multiplier starts at one. Each call prints n times that multiplier, then asks for the next multiplier.

When the multiplier exceeds ten, the function returns. For n equal to three, the final row is 3 × 10 = 30. The table has a fixed recursion depth even for a large entered number because only the multiplier controls stopping.

Does n = 0 work? Yes. It prints ten zero products.

Can n be negative? Yes. The multiplier still advances to eleven.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

What triggers the base case?

Pick an answer to check it.

Question 2

Does n = 0 work?

Pick an answer to check it.

Questions people ask

Does n = 0 work?

Yes. It prints ten zero products.

Can n be negative?

Yes. The multiplier still advances to eleven.

What triggers the base case?

multiplier > 10.