Simple Python code to print 2 times table (modifiable to all multiplication tables)

A printer wants to print a note book

And needs an application to help him come up with 2 times table

Write a code in PYTHON that prints out 2 times table up until 8.

To enable the printer print his note book

SOLUTION

Write down 2 times table up until 8

2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16

Print the first line of the 2 times table

print("2 * 1 = 2")

Put the increasing value in a variable

No alt text provided for this image

Use a for loop to print the code 8 times and increment the variable d at each time it loops

No alt text provided for this image

The result will be

2 * 1 = 2
2 * 2 = 2
2 * 3 = 2
2 * 4 = 2
2 * 5 = 2
2 * 6 = 2
2 * 7 = 2
2 * 8 = 2

Then replace the 2 on right with a computation of the result as seen in the codes below

No alt text provided for this image

Sign up for a free 1year mentorship at Females In Tech

Leave a Reply