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.
1def print_table_row(n, multiplier=1):2 # Base case3 if multiplier > 10:4 return56 # Print current row7 print(f"{n} × {multiplier} = {n * multiplier}")8 # Recurse9 print_table_row(n, multiplier + 1)1011# Test12n = 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
Return when multiplier exceeds ten.
- 2
Print n times the current multiplier.
- 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.
🔗Related Content
- 📖
Phase 3 - Learn Concepts
Review Phase 3 concepts and explanations
- 📝
Phase 3 - Quiz
Test your Phase 3 understanding with quiz questions
- 💻
Phase 3 - All Practice Problems
Explore all practice problems for Phase 3
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum