脚本如下:
# @Time : 2021/6/26 13:31 # @Author : cici #左上行号参数 row = 1 #右上行号2 row2 = 1 #左下行号3 row3 = 9 #右下行号4 row4 = 9 while row <= 9 and row2 <= 9: #列号参数 col = 1 while col <= row: print("%d*%d=%d"%(col,row,col*row), end="\t") #判断右上行号是否和左上列号一致,一致则执行循环体 while row2 == col: col2 = 9 while col2 >= row2: print("%d*%d=%d"%(row2,col2,row2*col2), end="\t") col2 -= 1 #内部循环结束后会返回到while处判断row2 == col,为了不死循环 row2 -= 1 col += 1 #为了把-1加回来将左右行数保持一致 row2 += 1 #换行语句 print("") #行号+1 row += 1 row2 += 1 while (row3 <= 9 and row3 >= 1) and (row4 <= 9 and row4 >= 1): col3 = 1 while col3 <= row3: print("%d*%d=%d" % (col3, row3, col3 * row3), end="\t") while col3 == row4: col4=9 while col4 >= row4: print("%d*%d=%d" % (col4, row4, row4 * col4), end="\t") col4 -= 1 row4 -= 1 col3 += 1 # 换行语句 print("") # 行号+1 row3 -= 1