Home Tutorials Python Programs Multiplication Table
Multiplication Table

Multiplication Table


Topic: Multiplication Table Generator

Description: This interactive program prompts the user to enter a specific integer and a preferred range limit. It then utilizes a loop structure to calculate and display a perfectly formatted mathematical multiplication table for that number up to the specified limit.

Why: This project introduces students to the core concepts of loops and iterations (specifically the for loop) and Python's built-in range() function. It also reinforces how to dynamically inject variables into text output using string interpolation structures (f-strings).


Program Code

Copy and run the following Python code to see the multiplication engine in action:

def generate_multiplication_table():
    print("=============================")
    print(" MULTIPLICATION TABLE ENGINE ")
    print("=============================")
    
    try:
        # Accept user input for the base number and target limit
        table_number = int(input("Enter the number for the table: ").strip())
        table_limit = int(input("Enter the multiplier limit: ").strip())
    except ValueError:
        print("\nError: Invalid input. Please enter valid whole numbers.")
        return

    print(f"\nMultiplication Table for {table_number} up to {table_limit}:")
    print("-----------------------------")

    # Loop from 1 up to and including table_limit
    for i in range(1, table_limit + 1):
        product = table_number * i
        # Output formatted equation row
        print(f"{table_number}  x  {i:2d}  =  {product}")
        
    print("-----------------------------")

# Execute the generator program
generate_multiplication_table()

Expected Console Output Examples

Example 1 (Standard 1 to 10 Table):

=============================
 MULTIPLICATION TABLE ENGINE 
=============================
Enter the number for the table: 7
Enter the multiplier limit: 10

Multiplication Table for 7 up to 10:
-----------------------------
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
-----------------------------

Example 2 (Custom Higher Range Table):

Enter the number for the table: 12
Enter the multiplier limit: 5

Multiplication Table for 12 up to 5:
-----------------------------
12  x   1  =  12
12  x   2  =  24
12  x   3  =  36
12  x   4  =  48
12  x   5  =  60
-----------------------------

Core Syntax & Concept Breakdown

  • The range(start, stop) Generator Sequence: In Python, the range() function

🏋️ Test Yourself With Exercises

Take our quiz on Multiplication Table to test your knowledge.

Browse Quizzes »