A Python Program to print multiplication table of any natural number

I am just beginning in the world of computer programming with python as my first language. Yesterday, I wrote a very simple program which, when executed, ask us for a number whose table we want to print, then a number from where we want to start the table and finally a number up to which the table will be printed. The source code of the program is:

def table(a, b, l):
while a<=l and b>1:
result = b*a
print b, "X", a , "=", result
a+=1
b = input("Tell me the number whose table you want to print... ")
a = input("Start the table from? ")
l = input("Print up to? ")
table(a, b, l)

A sample execution of this program in my python shell looks something like this:

>>> execfile('D:Python Practicepract.py')
Tell me the number whose table you want to print... 7
Start the table from? 1
Print up to? 10
7 X 1 = 7
7 X 2 = 14
7 X 3 = 21
7 X 4 = 28
7 X 5 = 35
7 X 6 = 42
7 X 7 = 49
7 X 8 = 56
7 X 9 = 63
7 X 10 = 70
>>>

Leave a Reply

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