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 https://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

Python program to print multiplication table using for loop

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<=10:  
    num = num * 1  
    print(num,'x',i,'=',num*i)  
    i += 1  

Output of the above code -

Enter the number : 5
Multiplication Table : 
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Python Print Multiplication Table from 1 to 10

In the given program, we will print the multiplication table from 1 to 10 using for loop.

# Multiplication table from 1 to 10 in Python
# using for loop

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

Output of the above code:

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

How do you make a multiplication table for a loop in Python?

Code using a for loop.
ourNum = int(input("Enter the number you want to generate a multiplication table for, then hit the `enter` key: ")).
ourRange = range(1,6).
for x in ourRange:.
result = ourNum * x..
print(ourNum," * ",x," = ",result).

How do you print a multiplication table for a loop?

Step 1: Enter a number to print table at runtime. Step 2: Read that number from keyboard. Step 3: Using for loop print number*I 10 times. // for(i=1; i<=10; i++) Step 4: Print num*I 10 times where i=0 to 10.

How do you print a multiplication table using nested loops in Python?

The following program uses a nested-for loop to display multiplication tables from 1-10. The print() function inner loop has end=' ' which appends a space instead of default newline. Hence, the numbers will appear in one row. Last print() will be executed at the end of inner for loop.

How do you print a multiplication in Python?

In python, to multiply number, we will use the asterisk character ” * ” to multiply number. After writing the above code (how to multiply numbers in Python), Ones you will print “ number ” then the output will appear as a “ The product is: 60 ”. Here, the asterisk character is used to multiply the number.