The times table
Section 4: LoopsLesson 4.2 · ⏱ 7 min
n = int(input("Which table? "))
for i in range(1, 11):
print(n, "x", i, "=", n * i)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Which table? 7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
📌 Another example: a table on request
We ask for the number, then print its table.
When the program asks, we type: 7.
n = int(input("Which table? "))
for i in range(1, 11):
print(n, "x", i, "=", n * i)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗Which table? 7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
The 9 times table from 1 to 5.
👀 Show the solution🙈 Hide the solution
for i in range(1, 6):
print(9, "x", i, "=", 9 * i)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45
Result: 9 x 1 = 9 … 9 x 5 = 45
Medium
The addition table: 5 + 1 up to 5 + 10.
👀 Show the solution🙈 Hide the solution
for i in range(1, 11):
print(5, "+", i, "=", 5 + i)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗5 + 1 = 6 5 + 2 = 7 5 + 3 = 8 5 + 4 = 9 5 + 5 = 10 5 + 6 = 11 5 + 7 = 12 5 + 8 = 13 5 + 9 = 14 5 + 10 = 15
Result: 5 + 1 = 6 … 5 + 10 = 15
Hard
The full times table from 1 to 5 (a loop inside a loop).
👀 Show the solution🙈 Hide the solution
for a in range(1, 6):
line = ""
for b in range(1, 6):
line = line + str(a * b) + " "
print(line)
🖥️ The output in Robo Python:
🐍 Open the code in Robo Python ↗1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25
Result: five lines, the last 5 10 15 20 25.

