Skip to main content

Learning outcomes

By the end of this lecture, you should be able to:
  • print multiplication table for one number
  • print tables for multiple numbers
  • format output for readability

Single table (1 to 10)

n = int(input("Enter number: "))
for i in range(1, 11):
    print(f"{n} x {i} = {n * i}")

Table with custom limit

n = int(input())
limit = int(input())
for i in range(1, limit + 1):
    print(f"{n} x {i} = {n*i}")

Multiple tables (2 to 5)

for n in range(2, 6):
    print(f"Table of {n}")
    for i in range(1, 11):
        print(f"{n:>2} x {i:>2} = {n*i:>3}")
    print()

Nested loop understanding

Outer loop chooses table number.
Inner loop prints one table entries.

Exam hints and traps

  • use limit + 1 for inclusive last row
  • reset inner-loop logic correctly per table
  • formatting alignment may be asked in output-prediction

Practice

  1. Print table of 7 till 15.
  2. Print tables from 3 to 5.
  3. Print table in reverse order (10 to 1).

Sample answer (reverse)

for i in range(10, 0, -1):
    print(f"{n} x {i} = {n*i}")