Multiplication Table in Python

Multiplication Table in Python | In this post, We will discuss how to print multiplication tables in python. In mathematics, a multiplication table is a mathematical table used to define a multiplication operation for an algebraic system. We will also develop a Python program to print multiplication tables from 1 to 10.

Give a number n as input, we need to print its table. Example:-

Input:- 5
Output:-
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Print Multiplication Table in Python

This is the simplest and easiest way to print a multiplication table in python. We will take a number while declaring the variables. Python program to print multiplication table using for loop.

# Python program to print multiplication table

# take inputs
num = int(input('Display multiplication table of: '))

# print multiplication table
for i in range(1, 11):
    print ("%d * %d = %d" % (num, i, num * i))

Output:-

Display multiplication table of: 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

In this program, inputs are scanned using the input() function and stored in the variable num.

num = int(input('Display multiplication table of: '))

Python program to print multiplication table using for loop.

for i in range(1, 11):
 print ("%d * %d = %d" % (num, i, num * i))

Here, we have used the for-loop along with the range() function to iterate 10 times. The arguments inside the range() function are (1, 11). Meaning, greater than or equal to 1 and less than 11.

Python Program using While Loop

In the previous program, print multiplication table using for loop but in this program, print multiplication table using while loop.

# Python program to print multiplication table

# take inputs
num = int(input('Display multiplication table of: '))

# print multiplication table
i = 1
while i <= 10:
    print ("%d * %d = %d" %(num, i, num * i))
    i = i+1

Output:-

Display multiplication table of: 8
8 * 1 = 8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
8 * 10 = 80

Python Program to Print Multiplication Table from 1 to 10

In this program, we will print a multiplication table from 1 to 10 using for loop. We need to use two loops which should be nested.

# Python program to print multiplication table from 1 to 10

print('Multiplication table from 1 to 10: ')
for i in range (1,11):
    print('\n')
    for j in range(1, 11 ):
        print (i*j, end='\t')

Output:-

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

Print Multiplication Table in given Range

The Below program can display the multiplication table in between two given numbers. Using this program we can print the multiplication table from m to n.

# Python program to print multiplication table in range

# take inputs
print('Display multiplication table')
start = int(input('Start: '))
end = int(input('End: '))

# print multiplication table
for i in range (start, end+1):
    print('\n\nMultiplication table of %d\n' %(i))
    for j in range(1, 11 ):
        print('%d * %d = %d\t' %(i, j, i*j))

Output:-

Display multiplication table
Start: 5
End: 6

Multiplication table of 5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50

Multiplication table of 6
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60

Also See:- Leap Year Program in Python

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *