Editor

Create a Multiplication Table

Beginner · Write the code · from Python Input and Output: print(), input(), and Formatting

From the lesson: Python Input and Output: print(), input(), and Formatting

Every program needs a way to talk to the outside world. A weather app shows temperatures. A game displays your score. A calculator prints answers. All of these use output.

Read the lesson

Create a multiplication table for numbers 1 through 3. Each product should be right-aligned and take up 4 characters of width. Print a header row and a separator line.

Expected output:

1   2   3
   -----------
1 |   1   2   3
2 |   2   4   6
3 |   3   6   9

Use f-string alignment ({value:>4}) to right-align numbers in 4-character columns.

# Print the header row
print(" ", end="")
for i in range(1, 4):
print(f"{i:>4}", end="")
print()
# Print the separator
print(" -----------")
# Print each row of the table
# Your code here

More Input and Output exercises

All Python exercises · 50 practice problems · Python Fundamentals quiz