Multiplication Table Recursively
Print multiplication table using recursion.
IntermediatePhase 3 - Level 3: Pattern RecursionExample 7 of 10
multiplication-table-recursively.py
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
Enter number: 5 5 × 1 = 5 5 × 2 = 10 5 × 3 = 15 ... 5 × 10 = 50
What's going on
Print row, then recurse with next multiplier.
Key Concepts:
Print current multiplication
Recurse with multiplier + 1
Base case when 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