Python Program to Display the multiplication Table


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

A multiplication table is a table that displays the products of two or more numbers. Typically, a multiplication table shows the products of all the numbers from 1 to 10 (or sometimes up to 12) in a grid format. The numbers are arranged in rows and columns, with the row and column headers indicating the numbers being multiplied. For example, the row and column headers of the multiplication table below are the numbers 1 to 10:


 x | 1  2  3  4  5  6  7  8  9  10  
----------------------------------
 1 | 1  2  3  4  5  6  7  8  9  10  
 2 | 2  4  6  8  10 12 14 16 18 20  
 3 | 3  6  9  12 15 18 21 24 27 30  
 4 | 4  8  12 16 20 24 28 32 36 40  
 5 | 5  10 15 20 25 30 35 40 45 50  
 6 | 6  12 18 24 30 36 42 48 54 60  
 7 | 7  14 21 28 35 42 49 56 63 70  
 8 | 8  16 24 32 40 48 56 64 72 80  
 9 | 9  18 27 36 45 54 63 72 81 90  
10 | 10 20 30 40 50 60 70 80 90 100  

In the example above, each cell contains the product of the number in its row and the number in its column. For instance, the product of 4 and 5 is found in the cell at the intersection of row 4 and column 5, which is 2


Python Code :

The Below Python program displays the multiplication table of a given number:


# Get input number from user
num = int(input("Enter a number: "))

# Display multiplication table
print("Multiplication table of", num)
for i in range(1, 11):
    print(num, "x", i, "=", num * i)


In this program, the user is prompted to enter a number. The program then displays the multiplication table for that number using a for loop.

To display the multiplication table, the program uses a for loop to iterate through the numbers 1 to 10 using the expression for i in range(1, 11). For each value of i, the program multiplies the input number by i and prints out the result using the print statement. The print statement uses string concatenation to display the equation, such as “2 x 1 = 2”.

Note that this program assumes that the user enters a valid integer. If the user enters an invalid input, such as a string or a non-numeric value, the program will raise a ValueError or produce an incorrect result.

For example :


Enter a number: 7
Multiplication table of 7
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


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co