TalentJR

🐍 Python for kids · Class 6 · Lesson 12 of 18 · Free

Project: Build a Multiplication Tool

⏱ About 35 minutes · ▶ run real Python here — nothing to install · no sign-in

In this lesson you will

  • Plan a program in small steps and test each step before the next.
  • Combine input, while loops, if, break and functions into one tool.
  • Format numbers in neat columns and print a full multiplication grid.

Before exams, everyone revises tables. Today you will build your own table machine. It checks what the user types, prints neat columns, and keeps going until the user says stop.

How do I print a multiplication table in Python?

Big programs are built in small steps. Step 1 is the simplest version that works.

Real programmers work this way too. They run the code after every small change, so bugs are easy to find.

We ask for a number, convert it with int(), and loop from 1 to 10.

The f-string builds each line, like 7 x 3 = 21. Python does the maths inside the curly brackets.

🎬 How Python thinks — step 1 of 23Python is about to run line 1
▶n = int(input("Which table? "))
2for i in range(1, 11):
3 print(f"{n} x {i} = {n * i}")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
Which table? 13
13 x 1 = 13
13 x 2 = 26
13 x 3 = 39
13 x 4 = 52
13 x 5 = 65
13 x 6 = 78
13 x 7 = 91
13 x 8 = 104
13 x 9 = 117
13 x 10 = 130

How do I let the user choose where the table ends?

Some students learn tables up to 10. Others go up to 20. Let the user decide.

A second input gives the last number. range(1, upto + 1) includes it, because range stops before its end.

To keep the columns straight, write {i:>2} in the f-string. It pads the number to 2 places, lined up on the right.

🐍 Python — you can edit this code
Output
Which table? 17
Up to which number? 12
17 x  1 =  17
17 x  2 =  34
17 x  3 =  51
17 x  4 =  68
17 x  5 =  85
17 x  6 = 102
17 x  7 = 119
17 x  8 = 136
17 x  9 = 153
17 x 10 = 170
17 x 11 = 187
17 x 12 = 204

💡 Remove the :>2 and :>3 and run again. The equals signs will no longer line up.

How do I check that the user typed a valid number?

If someone types "seven", int() crashes with a ValueError. A good tool should not crash.

isdigit() is True only when every character of a string is a digit. So check it before calling int().

A while True loop keeps asking until the answer is good. Then break lets the program move on.

🐍 Python — you can edit this code
Output
Which table (1-99)? seven
Please type digits only.
Which table (1-99)? 250
Choose a number from 1 to 99.
Which table (1-99)? 7
Great, making the table of 7

💡 This one loop uses not, or, continue and break – all from earlier lessons.

How do I put the table inside a function?

Now the table code works, so we give it a name. A function lets us reuse it with any number.

print_table(n, upto) takes two parameters. It also returns the sum of all answers, just for fun.

Calling the function twice prints two different tables. We wrote the loop only once.

In the trace, see how n and upto get their values when the function is called.

🎬 How Python thinks — step 1 of 16Python is about to run line 1
▶def print_table(n, upto):
2 total = 0
3 for i in range(1, upto + 1):
4 print(f"{n} x {i} = {n * i}")
5 total = total + n * i
6 return total
7
8answer_sum = print_table(4, 3)
9print("Sum of answers:", answer_sum)
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
Sum of answers: 24

How do I make the tool repeat until the user quits?

A real tool should not end after one table. We wrap everything in a while True loop.

Each round, the user types a number or q. The word q breaks out of the loop.

We also keep a list of the tables made. At the end, it is printed as a small report.

Notice the bad input abc does not stop the tool. continue simply asks again.

🐍 Python — you can edit this code
Output
Table number, or q to quit: 6
6 x  1 =   6
6 x  2 =  12
6 x  3 =  18
6 x  4 =  24
6 x  5 =  30
Table number, or q to quit: abc
That is not a number.
Table number, or q to quit: 9
9 x  1 =   9
9 x  2 =  18
9 x  3 =  27
9 x  4 =  36
9 x  5 =  45
Table number, or q to quit: q
Tables you made: [6, 9]

How do I print a full multiplication grid with nested loops?

A grid shows every table from 1 to 10 at once. It is like the chart at the back of a notebook.

The outer loop picks the row. The inner loop walks across the columns of that row.

Each box holds row * col. So row 7, column 8 shows 56, the answer to 7 x 8.

end="" keeps the inner prints on one line. The empty print() after the inner loop starts a new row.

🐍 Python — you can edit this code
Output
   1   2   3   4   5   6   7   8   9  10
   2   4   6   8  10  12  14  16  18  20
   3   6   9  12  15  18  21  24  27  30
   4   8  12  16  20  24  28  32  36  40
   5  10  15  20  25  30  35  40  45  50
   6  12  18  24  30  36  42  48  54  60
   7  14  21  28  35  42  49  56  63  70
   8  16  24  32  40  48  56  64  72  80
   9  18  27  36  45  54  63  72  81  90
  10  20  30  40  50  60  70  80  90 100

💡 Each number takes 4 spaces because of :>4. That keeps every column perfectly straight.

🤔 Predict the output

Think like Python: read the code and choose what it prints. You get the reason straight away.

Question 1. What does this print?

n = 6
for i in range(2, 5):
    print(n * i)

Question 2. What does this print?

print("12".isdigit(), "12a".isdigit(), "-5".isdigit())

Question 3. What does this print?

count = 0
for row in range(1, 4):
    for col in range(1, 4):
        if row * col > 3:
            count = count + 1
print(count)

🧩 Your challenge

Add a quiz mode to the tool. Ask the user which table to practise. Then ask 5 questions (n x 1 to n x 5). Count the right answers, keep a list of the questions they got wrong, and print the score and the wrong list at the end.

Expected output (with the inputs given):
Which table to practise? 8
8 x 1 = 8
8 x 2 = 16
8 x 3 = 25
8 x 4 = 32
8 x 5 = 45
Score: 3 out of 5
Revise these: ['8 x 3', '8 x 5']
🐍 Python — you can edit this code

⚠️ Common mistakes (and how to fix them)

❌ Wrong

n = input("Which table? ")
for i in range(1, 4):
    print(n * i)

No error message – but it prints 5, 55 and 555 instead of 5, 10 and 15.

✅ Right

n = int(input("Which table? "))
for i in range(1, 4):
    print(n * i)

input() gives text, and text times a number repeats the text. Convert with int() first.

❌ Wrong

n = 9
for i in range(1, 10):
    print(f"{n} x {i} = {n * i}")
print("Table complete up to 10!")

No error message – but the table stops at 9 x 9. The line for 9 x 10 is missing.

✅ Right

n = 9
for i in range(1, 11):
    print(f"{n} x {i} = {n * i}")
print("Table complete up to 10!")

range stops just before its end number. To include 10, the end must be 11.

❌ Wrong

text = input("Which table? ")
n = int(text)
if text.isdigit():
    print(n * 2)

ValueError: invalid literal for int() with base 10: 'ten'

✅ Right

text = input("Which table? ")
if text.isdigit():
    n = int(text)
    print(n * 2)
else:
    print("Digits only, please.")

The check came too late. int() crashed on the bad text before isdigit() could protect it.

📌 Remember

  • Build a program in small steps and run it after each step.
  • range(1, upto + 1) makes a table that includes the last number.
  • {x:>3} in an f-string lines numbers up in neat columns.
  • Check text with isdigit() before int(), so the tool never crashes.
  • A function lets you print any table without copying the loop.
  • while True with break keeps the tool running until the user quits.

Finished the quiz and the challenge?

Questions students ask

How do I write a multiplication table program in Python?

Read a number with int(input()). Then loop for i in range(1, 11): and print n * i each time.

How do I stop my Python program crashing on wrong input?

Check the text first with isdigit(). Only call int() when the check is True, and ask again otherwise.

What does :>3 mean inside an f-string?

It means: use 3 spaces for this value and push it to the right. This lines up numbers of different lengths.

Why use a function for the table?

The loop is written once and used many times. If you change the style, every table gets the change.