Solution Design In the first part of the program, print out the horizontal number labels and separating line. You
can program these two lines directly with two print() calls:
print(' | 1 2 3 4 5 6 7 8 9 10')
print('--+------------------------------')
Remember that you need the appropriate amount of spaces in between the numbers so the
columns of the multiplication table to line up. You can treat all numbers as though they were two
digits. The single-digit numbers should have a space printed on their left side, making the string right-
justified. Python’s rjust() string method can do this for you. Enter the following into the
interactive shell:
>>> '42'.rjust(4)
# Adds two spaces. ' 42'
>>> '042'.rjust(4)
# Adds one space. ' 042'
>>> '0042'.rjust(4)
# Adds zero spaces. '0042'
Notice how all of the strings returned from the rjust(4) call are four characters long. If the
original string is less than four characters long, the rjust() method puts spaces on the left side of
the returned string until it is four characters long.
To print out the multiplication table, two nested for loops can iterate over each product. The
outermost for loop iterates over the numbers of each row, and the innermost for loop iterates over
the numbers of each column in the current row. You don’t want a newline to appear after each
product, but only after each row of products. Python’s print() function automatically adds a
newline to the end of the string you pass. To disable this, pass a blank string for the end keyword
argument like print('Some text', end='').
A simplified version of this code would look like this:
>>> for row in range(1, 11):
... for column in range(1, 11):
... print(str(row * column) + ' ', end='')
... print()
# Print a newline. ...
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
Your solution needs these products appropriately aligned as well as the number labels along the
top and left side.