← Back to Nested Loops
✖️

Times Table

3 of 6

Exercise 2: Times Table

Print the full times table for a given number (1 through 12).

Example for number = 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
7 x 11 = 77
7 x 12 = 84

Starter Code

number = 7 for i in range(___): print(f"{number} x {i} = {___}")

Hints

Hint 1 — What range?

You want i to go from 1 to 12. Use range(1, 13).

Hint 2 — What to calculate?

The result is number * i. Use an f-string to format it nicely.


Bonus Challenge

Print times tables for numbers 1 through 5, with a blank line between each:

--- 1 Times Table ---
1 x 1 = 1
1 x 2 = 2
...

--- 2 Times Table ---
2 x 1 = 2
...
Bonus Hint

Use a nested loop! Outer loop goes through each number (1-5), inner loop goes 1-12.


Solution

Show Solution
number = 7 for i in range(1, 13): print(f"{number} x {i} = {number * i}")
Show Bonus Solution
for number in range(1, 6): print(f"--- {number} Times Table ---") for i in range(1, 13): print(f"{number} x {i} = {number * i}") print() # Blank line between tables
💻

Try it yourself

Code: Times Table

Loading Python runtime…
Python
Loading...
Output
Click "Run" to execute your code...
ℹ️ About this Python environment

✅ Standard library: heapq, collections, itertools, math, random, functools, datetime, bisect

✅ Functions, classes, recursion, print()

❌ No file system, subprocess, OS access, or network requests

❌ No pip install (all supported modules are pre-loaded)

⏱️ 5 second execution time limit