On this tutorial you’re going to learn how to build a Multiplication table of a given number in Python .
We are are going to use the concept of for loop in generating our table
Program overview
Our program will prompt a user to Enter a given number for multiplication table generation and limit number to restrict our table to a given number .
Program Instructions summary
- Entering a number for table generation
- Entering limit number of the table
- Generating and printing our table using for loop and print () function
table.py
#Getting number and limit from user number = int(input('Enter any number: ')) limit = int(input('Enter Limit of table: ')) for n in range(1, limit+1): product = number * n print(number, ' * ', n, ' = ', product)
Running Our Program
kalebu@kalebu-PC:~$ python table.py Enter any number: 14 Enter Limit of table: 6 14 * 1 = 14 14 * 2 = 28 14 * 3 = 42 14 * 4 = 56 14 * 5 = 70 14 * 6 = 84 --------------------------------------- kalebu@kalebu-PC:~$ python table.py Enter any number: 15 Enter Limit of table: 3 15 * 1 = 15 15 * 2 = 30 15 * 3 = 45
Hope you find this post interesting , don’t forget to subscribe to get more tutorials like this
In case of any suggestion or comment , drop it on the comment box and I will reply to you immediately.