Print 99 multiplication table
For Loop statement implementation:
For I in Range (1,10): A for J in range (1,10): print (J, "X", I, "=", i*j, "\ T", end= "") #因为print自动换行, end= "" ending with no newline if i==j: print ("") #此处是结尾换行 break
While loop statement implementation:
I=0j=0while i <9: i+=1 while J <9: j + = 1 print (J, "X", I, "=", I * j, "\ T", end= "") if I==j : print ("") j=0 break
Output Result:
1 x 1 = 1 1 x 2 = 2 2 x 2 = 4 1 x 3 = 3 2 x 3 = 6 3 x 3 = 9 1 x 4 = 4 2 x 4 = 8 x 3 = 4 x 4 = 4 1 x 5 = 5 3 x 5 = 4 x 5 = 5 x 5 = 1 x 6 = 6 2 x 6 = 3 x 6 = 4 x 6 = 5 x 6 = 6 x 6 = 1 7 x 7 = 2 7 X 7 = 4 x 7 = 5 x 7 = 6 x 7 = 7 x 7 = 1 x 8 = 8 2 x 8 = 3 x 8 = 4 x 8 = 5 x 8 = 6 x 8 = 8 x 8 = 1 x 9 = 9 2 x 9 = 3 x 9 = 4 x 9 = 5 x 9 = 6 x 9 = 7 x 9 = 8 x 9 = 9
Python applet exercise: Loop statement for,while implementation 99 multiplication table