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:
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 or suggestions on this Python program.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.