Python Program to Print the Multiplication Table

In this post, I will be discussing how to write a Python Program to print the Multiplication table.

To make this program, I will be using for loop.

I will be discussing two ways to print the multiplication table.

  1. Without using format() function
  2. With using format() function

Let's see the python code of the program.


Python Program to print the Multiplication table (Without using format() function)

In this method, I will just use the print() function.

Code:-

# taking input of the number of which you want multiplication table
num = int(input("Enter a number: "))                            

# using for loop to print the table
for i in range(1,11):  
    # printing the table normally
    print(num,'X',i,'=',num*i)                                              

Output:-

Enter a number: 13
13 X 1 = 13
13 X 2 = 26
13 X 3 = 39
13 X 4 = 52
13 X 5 = 65
13 X 6 = 78
13 X 7 = 91
13 X 8 = 104
13 X 9 = 117
13 X 10 = 130



Python Program to print the Multiplication table (By using format() function)

In this program code, I have used the print() function and as well as format() function.

The format() function is used to print the output in a more organized way.

Code:-

# taking input of the number of which you want multiplication table
num = int(input("Enter a number: "))                            

# using for loop to print the table
for i in range(1,11):                                           
    # printing the table using format() function
    print("{0:<3d} X {1:3d} = {2:<3d}".format(num,i,num*i))

Output:-

Enter a number: 13
13  X   1 = 13
13  X   2 = 26
13  X   3 = 39
13  X   4 = 52
13  X   5 = 65
13  X   6 = 78
13  X   7 = 91
13  X   8 = 104
13  X   9 = 117
13  X  10 = 130

Hence, we have discussed all the ways. I have also used the format() function in the python program to check for leap years.

You can learn about many other Python Programs Here.







The following two tabs change content below.

Amit Rawat

Founder and Developer at SpiderLabWeb
I love to work on new projects and also work on my ideas. My main field of interest is Web Development.

You may also like...