Write a program to print the table of a given number in Python | Code

To print the table of a given number first take an input integer number from the user in Python. Then we have iterated for loop using the range (1, 11) function.

In the first iteration, the loop will iterate and multiply by 1 to the given number. In the second iteration, 2 is multiplied by the given number, and so on.

Example print the table of a given number in Python

Simple example code using while loop and for loop in Python.

Using For loop

num = int(input("Enter the number: "))

for count in range(1, 11):
    print(num, 'x', count, '=', num * count)

Output:

Write a program to print the table of a given number in Python

Using While Loop

num = int(input("Enter the number: "))
count = 1

while count <= 10:
    num = num * 1
    print(num, 'x', count, '=', num * count)
    count += 1

Output:

Enter the number: 9
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
9 x 10 = 90

Do comment if you have any doubts and suggestions on this Python program.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.