Print table in python 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.

I'm trying to create a table that looks like this:

 0 1 2 3 4 5 6 7 8 9
 10 11 12 13 14 15 16 17 18 19
 20 21 22 23 24 25 26 27 28 29
 30 31 32 33 34 35 36 37 38 39
 40 41 42 43 44 45 46 47 48 49

I was able to get it done by doing this:

for x in range(0, 50, 10):
    print(x, x + 1, x + 2, x + 3, x + 4, x + 5, x + 6, x + 7, x + 8, x + 9)

But it seems like this definitely isn't the most efficient way to do it. I've tried adding:

    # for y in range(1, 10):
        # print(x, x + y)

after the first for loop in my original code, but it doesn't work.

Thank you!

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

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

Print table in python 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

How do you print a nested for loop table 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 table?

Here, the user input is stored in the int variable n . Then, we use a for loop to print the multiplication table up to 10. The loop runs from i = 1 to i = 10 . In each iteration of the loop, n * i is printed.

How do you make a table in Python?

How to Easily Create Tables in Python.
install tabulate. We first install the tabulate library using pip install in the command line: pip install tabulate..
import tabulate function. ... .
list of lists. ... .
dictionary of iterables. ... .
missing values..

How do you write a while loop table?

Program to generate the table of a number using while loop.
#include <stdio.h>.
int main().
int num, i = 1; // declare a variable..
printf (" Enter a number to generate the table in C: ");.
scanf (" %d", &num); // take a positive number from the user..
printf ("\n Table of %d \n ", num);.