انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Python: home
0. Lab tour1
1. The start5
2. Variables and input5
3. Conditions5
4. Loops5
5. Lists4
6. Functions4
7. Drawing with the turtle3
8. The project: the guess-the-number game3
9. Strings in depth1
10. Dictionaries (dict)3
11. Randomness and errors3
12. Classes and objects (class)2
13. Pro drawing and charts3
14. The final project: the quiz game2

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:
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
🐍 Open the code in Robo Python ↗

📌 Another example: a table on request

We ask for the number, then print its table.

When the program asks, we type: 7.

🐍 A table on request
n = int(input("Which table? "))
for i in range(1, 11):
    print(n, "x", i, "=", n * i)
🖥️ The output 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
🐍 Open the code in Robo Python ↗
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

The 9 times table from 1 to 5.

👀 Show the solution
🐍 Solution
for i in range(1, 6):
    print(9, "x", i, "=", 9 * i)
🖥️ The output in Robo Python:
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
🐍 Open the code in Robo Python ↗

Result: 9 x 1 = 9 … 9 x 5 = 45

Medium

The addition table: 5 + 1 up to 5 + 10.

👀 Show the solution
🐍 Solution
for i in range(1, 11):
    print(5, "+", i, "=", 5 + i)
🖥️ The output 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
🐍 Open the code in Robo Python ↗

Result: 5 + 1 = 6 … 5 + 10 = 15

Hard

The full times table from 1 to 5 (a loop inside a loop).

👀 Show the solution
🐍 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:
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
🐍 Open the code in Robo Python ↗

Result: five lines, the last 5 10 15 20 25.

Finished the lesson? Mark it so your progress counts.