Founding Batch Offer · HLD · LLD · System Design at ₹799 until 30 Nov

Print Multiplication Table

Build a ten-row multiplication table from an entered integer. Students use range, a temporary result, and formatted output that labels every multiplication.

BeginnerPhase 2 - Level 1: Basic LoopingExample 7 of 14
print-multiplication-table.py
1# Take n as input
2n = int(input("Enter a number: "))
3
4# Print multiplication table
5print(f"Multiplication table of {n}:")
6for i in range(1, 11):
7 result = n * i
8 print(f"{n} × {i} = {result}")

Output

...

The sample abbreviates a longer result. The program prints the intervening values; it does not print these dots.

In this one

  • Keep one operand fixed
  • Calculate products in a loop
  • Format labelled rows

How it works

  1. 1

    Read n and print the heading.

  2. 2

    Visit multipliers one through ten and compute n * i.

  3. 3

    Print the labelled equation for each multiplier.

Edge cases

Does zero work?

Does zero work?

Yes. Every product is zero.

Can n be negative?

Can n be negative?

Yes. The ten multipliers are positive and the products carry n's sign.

What's going on

The entered number stays fixed while i runs from one through ten. Each iteration computes a new result using n * i.

The heading prints once before the loop. The row print then inserts n, i, and result into an f-string. With n equal to three, the row for i equal to four reads 3 × 4 = 12; this uses arithmetic multiplication, not repeated text.

Does zero work? Yes. Every product is zero.

Can n be negative? Yes. The ten multipliers are positive and the products carry n's sign.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

What changes on each row?

Pick an answer to check it.

Question 2

Does zero work?

Pick an answer to check it.

Questions people ask

Does zero work?

Yes. Every product is zero.

Can n be negative?

Yes. The ten multipliers are positive and the products carry n's sign.

What changes on each row?

i and result.