Display Multiplication Table in Python

In this Python lesson, we will practice how to generate the multiplication table using any number. We are going to allow a user to choose any number and we will generate the multiplication table based on user input. Let’s start with the first practice and kick off immediately.

Example: Create a Multiplication Table from 1 to 10

# request input from the user
num = int(input('Enter a number: '))

# Iterate 10 times from i (ie 1 to 10)
for i in range(1, 11):
   print('{0} x {1} = {2}'.format(num,i,num*i))

Output

Enter a number: 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

In the example above, the user only chooses the number he wants to generate the table for and we generated the table from 1 to 10 only. The arguments inside the range() function are (1, 11). Meaning, greater than or equal to 1 and less than 11. You can extend this table to your choice.

Do you want to become an expert programmer? See books helping our students, interns, and beginners in software companies today (Click here)!

Leave a Comment

Python Tutorials