Zed-King Institute

    Python Program to Print a Multiplication Table

    easyfor loopPython

    The first loop program most students write. It shows how range() produces the numbers a loop walks through.

    The question

    Read an integer n and print its multiplication table from 1 to 10 in exactly this format: n x i = product (one line each).

    The code

    program.py

    n = int(input())
    for i in range(1, 11):
        print(n, "x", i, "=", n * i)

    Input

    14

    Output

    14 x 1 = 14
    14 x 2 = 28
    14 x 3 = 42
    14 x 4 = 56
    14 x 5 = 70
    14 x 6 = 84
    14 x 7 = 98
    14 x 8 = 112
    14 x 9 = 126
    14 x 10 = 140

    How it works

    1. 1range(1, 11) gives 1, 2 … 10 — the end value 11 is not included.
    2. 2For each i, n * i is the next line of the table.
    3. 3print(n, "x", i, "=", n * i) puts one space between each item automatically.

    Common mistakes

    • Writing range(1, 10), which stops at 9 and misses the last line.
    • Joining numbers and text with + — Python cannot add a number to a string without str().

    Now solve a similar question yourself

    A new Python question every time, checked instantly.

    Practice questions

    More in for loop