Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
In this capstone project for Chapter 13, we integrate all loop constructs—including for loops, while loops, nested loops, break, continue, pass, loop-else clauses, and list comprehensions—to engineer a comprehensive, multi-mode Mathematical Multiplication & Grid Engine.
Every Indian school student is familiar with learning “Pahade” (multiplication tables from 2 to 20). In computing, multiplication tables are more than simple arithmetic drills: they are the foundation of 2D coordinate transformation, matrix operations in machine learning, and cryptographic modular arithmetic.
Our engine provides three distinct operating modes:
while-else and break to test mathematical speed and calculate accuracy scores.Here is the complete, production-grade Python script:
Let us execute the functions to test single tables, a 2D matrix, and the speed drill:
Output:
+====================================+
| PAHADA / TABLE FOR 19 |
+====================================+
| Multiple Factor Product |
+------------------------------------+
| 19 x 1 = 19 |
| 19 x 2 = 38 |
| 19 x 3 = 57 |
| 19 x 4 = 76 |
| 19 x 5 = 95 |
| 19 x 6 = 114 |
| 19 x 7 = 133 |
| 19 x 8 = 152 |
| 19 x 9 = 171 |
| 19 x 10 = 190 |
+====================================+
+=======================================================+
| 2D MULTIPLICATION GRID (1 to 8) |
+=======================================================+
X | 1 2 3 4 5 6 7 8
-------+------------------------------------------------
1 | 1 2 3 4 5 6 7 8
2 | 2 4 6 8 10 12 14 16
3 | 3 6 9 12 15 18 21 24
4 | 4 8 12 16 20 24 28 32
5 | 5 10 15 20 25 30 35 40
6 | 6 12 18 24 30 36 42 48
7 | 7 14 21 28 35 42 49 56
8 | 8 16 24 32 40 48 56 64
+=======================================================+
=== MULTIPLICATION SPEED DRILL: TABLE OF 14 ===
Goal: Answer 3 questions accurately.
Q1: What is 14 x 7?
--> [CORRECT] 14 x 7 = 98
Q2: What is 14 x 3?
--> [CORRECT] 14 x 3 = 42
Q3: What is 14 x 11?
--> [CORRECT] 14 x 11 = 154
--> [DRILL COMPLETE] All challenge questions finished successfully.
Drill Accuracy: 100.0% (3/3 Correct)1 to 10. By accepting start_multiple and end_multiple, it supports arbitrary mathematical intervals (such as calculating multiples from 11 to 20).{val:>3} (right-aligned, width 3) or {val:^6} (centered, width 6) ensures that single-digit and multi-digit products maintain straight vertical table borders.print_2d_multiplication_matrix, each row represents an outer iteration, while columns are printed horizontally using end="" before issuing a terminal print() to drop down to the next row.[random.randint(1, 12) for _ in range(count)].range(start, end + 1).print(..., end="") combined with f-string width formatting ({val:>4}).while-else construct ensures that completion summaries trigger only when all challenge questions conclude without early aborts.If you forget to update your loop counter inside a while loop, the condition remains True forever:
Removing or inserting items in a list while looping over it causes skipped elements:
A. continue B. print() (or print("\n")) C. pass D. break
A. $2 \times N$ B. $N^2$ C. $N + 1$ D. $N!$
A. {val:<5} B. {val:>5} C. {val:^5} D. {val:5r}
start_multiple is greater than end_multiple in range(start_multiple, end_multiple + 1) without specifying a negative step?A. Python raises a ValueError B. The loop body does not execute at all (0 iterations) C. The loop executes in reverse automatically D. Python runs in an infinite loop
[n * i for i in range(1, 11)] preferred for generating table products programmatically?A. It compiles the products directly into a clean list in high-performance C bytecode B. It automatically prints the table to the console C. It sorts the numbers in descending order D. It prevents negative numbers from existing
In Vedic Mathematics, the sutra "Ekadhikena Purvena" (By one more than the previous one) provides an instant mental shortcut to calculate the square of any two-digit number ending in 5 (e.g. 15, 25, 35, ... 95):
25.25 $\rightarrow 1225$. Verify: $35 \times 35 = 1225$!for loop to iterate over all two-digit numbers ending in 5 from 15 to 95: range(15, 100, 10).num * num).tens = num // 10vedic_prefix = tens * (tens + 1)vedic_result = int(f"{vedic_prefix}25")num * num == vedic_result.In the next lesson, we will continue your Python learning journey with Defining & Calling Functions (14: Functions).
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Looping Techniques with enumerate() and zip() | Defining & Calling Functions |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.