Print the 9-9 multiplication table using Python loops (including while & for) and pythonwhile
I. Print the 9-9 multiplication table in a for Loop
# Note: Due to the poor control of indentation in the browser, please forgive me. images will be imported later.
1.1 lower left corner
For I in range (1, 10 ):
For j in range (1, I + 1 ):
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
Print ()
:
1.2 bottom right corner
For I in range (1, 10 ):
For k in range (I + 1, 10 ):
Print (end = '') # Eight spaces are returned. Note that
For j in range (1, I + 1 ):
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
Print ()
1.3 upper left corner
For I in range (9, 0,-1 ):
For j in range (1, I + 1 ):
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
Print () # The main purpose here is to use the print feature for line feed.
1.4 upper right corner
For I in range (1, 10 ):
For k in range (1, I ):
Print (end = '') # Eight spaces are returned.
For j in range (9, I-1,-1 ):
Print ('% d * % d = % 2d \ t' % (I, j, I * j), end = '')
Print ()
Ii. while loop print multiplication table (four methods)
2.1Lower left corner
I = 1
While I <= 9:
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (I, j, I * j), end = '')
J + = 1
Print ()
I + = 1
:
2.2 bottom right corner
I = 1
While I <= 9:
K = 9
While k> I:
Print (end = '') # There are eight spaces.
K-= 1
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
J + = 1
Print ()
I + = 1
2.3 upper left corner
I = 9
While I> = 1:
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
J + = 1
I-= 1
Print ()
2.4 upper right corner
I = 9
While I> = 1:
K = 9
While k> I:
Print (end = '') # There are eight spaces.
K-= 1
J = 1
While j <= I:
Print ('% d * % d = % 2d \ t' % (j, I, I * j), end = '')
J + = 1
Print ()
I-= 1
Later: the source code is used for reference only.