Use Python loop (including while & for) to print the 9-9 multiplication table instances, 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 (): for k in range (I +): 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 (): for k in range (1, I): print (end = '') # Eight spaces 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.1 lower 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 = '') # 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 = '') # 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.
The above example of printing the 9-9 multiplication table using the Python loop (including while & for) is all the content shared by the editor. I hope to give you a reference, we also hope that you can support the customer's home.