Javatpoint Logo
Javatpoint Logo

Python Program to Display the Multiplication Table

In Python, the user can write the program to display the multiplication table of any number. In this tutorial, we will discuss different methods for printing the multiplication table of any number using Python.

Method 1: Using For loop

In the following example, we will print the multiplication table of any number (from 1 to 10) by using the for loop.

Example:

Output:

Enter the number : 10
Enter the number of which the user wants to print the multiplication table:  13
The Multiplication Table of:  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

Explanation:

In the above program, we have taken an input integer number from the user. Then we have iterated for loop using the range (1, 11) function, which means greater than or equal to 1 and less than 11. In the first iteration, the loop will iterate and multiply by 1 to the given number. In the second iteration, 2 is multiplied by the given number, and so on.

In our case, we have printed the table of 10. You can provide the different numbers to test the program.

Method 2: By using While Loop

In this method, we will use the while loop for printing the multiplication table of any number specified by the user.

The following is the example for method 2:

Example:

Output:

Enter the number of which the user wants to print the multiplication table:  27
The Multiplication Table of:  27
27 x 10 = 27
27 x 10 = 54
27 x 10 = 81
27 x 10 = 108
27 x 10 = 135
27 x 10 = 162
27 x 10 = 189
27 x 10 = 216
27 x 10 = 243
27 x 10 = 270

Explanation:

The above code is the same as the previous program, but we have used the while loop. We declared a variable "count" and initialized it by 1. The while loop will iterate until the value of "count" is smaller than and equal to 10. Each time loop is iterated, the value of "count" will be incremented by 1. When the "count" became greater than 10, the loop will be terminated.

Conclusion

In this tutorial, we have discussed two different methods which can be used for printing the multiplication table of any number using Python.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA