Site icon T4Tutorials.com

Multiplication Table in Python [for loop, while loop]

Write a Program in Python to Display the Multiplication Table.

Multiplication Table Program using for loop

GivenNumber= int(input ("Please Enter the number for which the user wants to print the multiplication table: "))      
# Here, The "for loop" will run to iterate the multiplication 20 times       
print ("The Multiplication Table of: ", GivenNumber)    
for counting in range(1, 21):      
   print (GivenNumber, 'x', counting, '=', GivenNumber * counting)

Output

Please Enter the number for which the user wants to print the multiplication table: 19
The Multiplication Table of: 19
19 x 1 = 19
19 x 2 = 38
19 x 3 = 57
19 x 4 = 76
19 x 5 = 95
19 x 6 = 114
19 x 7 = 133
19 x 8 = 152
19 x 9 = 171
19 x 10 = 190
19 x 11 = 209
19 x 12 = 228
19 x 13 = 247
19 x 14 = 266
19 x 15 = 285
19 x 16 = 304
19 x 17 = 323
19 x 18 = 342
19 x 19 = 361
19 x 20 = 380

Multiplication Table Program using while loop

Number=int(input("Please enter the desired number"))
Limit=int(input("Please Enter the maximum range number to which you want to print table"))
LoopVariable=1
while LoopVariable<=Limit:
    print(Number,"x",LoopVariable,"=",Number*LoopVariable)
    LoopVariable=LoopVariable+1

Output

Please enter the desired number17
Please Enter the maximum range number to which you want to print table12
17 x 1 = 17
17 x 2 = 34
17 x 3 = 51
17 x 4 = 68
17 x 5 = 85
17 x 6 = 102
17 x 7 = 119
17 x 8 = 136
17 x 9 = 153
17 x 10 = 170
17 x 11 = 187
17 x 12 = 204

Exit mobile version