Display the multiplication table in Python

In this article we have prepared a program to calculate and display multiplication table, using for loop for any number provided by user.

Program to get product table using range function

# Multiplication table (from 1 to 10) in Python

# Uncomment below line to take input from the user
# num = int(input("Get multiplication table for: "))
# Comment the below line and uncomment above line if you want to take input from user take
num = 12

# Below loop will iterate 10 times starting from 1 to 10
for i in range(1, 11):
  print(num, 'x', i, '=', (num * i))

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

Uncomment num = int(input("Get multiplication table for? ")) line if you want to take input from user. For illustrating example we’ve assign a fix value to num variable i.e 12.

The range(1, 11) function will iterate from 1 to 10 i.e 10 times. First argument(1) specified in range(1, 11) function will be inclusive and second argument(11) will be excluded from range.

You can also try with different loops.

Hope you like this!

Keep helping and happy 😄 coding

Avatar

A web geek, an industry experienced web developer & tutor/instructor residing in India 🇮🇳

Next
Previous

Related