Python program to print multiplication table using for loop

In the program below, we have used the for loop to display the multiplication table of 12.

Source Code

# Multiplication table [from 1 to 10] in Python

num = 12

# To take input from the user
# num = int[input["Display multiplication table of? "]]

# Iterate 10 times from i = 1 to 10
for i in range[1, 11]:
   print[num, 'x', i, '=', num*i]

Output

12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120

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.

We have displayed the multiplication table of variable num [which is 12 in our case]. You can change the value of num in the above program to test for other values.

Home / Python Examples / Python Program to Print Multiplication Table of a given Number

In this tutorial, we will see a simple Python program to display the multiplication table of a given number.

In the program, user is asked to enter the number and the program prints the multiplication table of the input number using for loop. The loops run from 1 to 10 and the input number is multiplied by the loop counter in each step to display the steps of multiplication table.

# Program published on //beginnersbook.com

# Python Program to Print Multiplication Table of a Number

num = int[input["Enter the number: "]]

print["Multiplication Table of", num]
for i in range[1, 11]:
   print[num,"X",i,"=",num * i]

Output:

Enter the number: 6
Multiplication Table of 6
6 X 1 = 6
6 X 2 = 12
6 X 3 = 18
6 X 4 = 24
6 X 5 = 30
6 X 6 = 36
6 X 7 = 42
6 X 8 = 48
6 X 9 = 54
6 X 10 = 60

Related Python Example:

1. Python program to find the sum of n natural numbers
2. Python program to add digits of a number
3. Python program for addition, subtraction, multiplication and division
4. Python program to swap two numbers

In this article, you will learn how to write a Python program to print multiplication table. Such a type of question is generally asked in programming interview.

Python multiplication table using for loop

Here, we have used the for loop to print the multiplication table. First, we have taken the input number from the user. Then we have iterated 10 times using for loop range[1, 11] function. In the initial iteration, the loop iterates and multiplies by 1 the given number. In the second iteration, 2 is multiplied by the given number, and so on.

# Multiplication table in Python
# using for loop

num = int[input["Enter the number : "]]    
i = 1

# using for loop to iterate multiplication 10 times    
print["Multiplication Table : "]

for i in range[1, 11]:
   print[num,'x',i,'=',num*i] 

Output of the above code -

Enter the number : 7
Multiplication Table : 
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
Enter the number : 16
Multiplication Table : 
16 x 1 = 16
16 x 2 = 32
16 x 3 = 48
16 x 4 = 64
16 x 5 = 80
16 x 6 = 96
16 x 7 = 112
16 x 8 = 128
16 x 9 = 144
16 x 10 = 160

Python multiplication table using while loop

In the given program, we have used the while loop to print the multiplication table in Python. We have declared a variable i and initialized it by 1. Next, we will iterate the while loop until the value of i is smaller and equal to 10. In each iteration, the value of i is incremented by one and multiplied by the num variable. The loop is terminated when the value of i becomes greater than 10.

# Multiplication table in Python
# using while loop

num = int[input["Enter the number : "]]    
i = 1

# using while loop to iterate multiplication 10 times    
print["Multiplication Table : "]

while i

Chủ Đề