#1.for循环 rows,cols = xrange(1,10),xrange(1,10) row,col = 1,1 for row in rows: for col in cols: if col <= row: print ‘%d*%d=%d\t‘ % (col,row,col*row), #\t代表tab键, 逗号确保同rows在同一行 print #打印空格,确保同col在同一列 可以简化为: for rows in xrange(1,10): for cols in xrange(1,10): if cols <= rows: print ‘%d*%d=%d\t‘ % (cols,rows,cols*rows), print #2.while循环 row = 1 while row <= 9: col = 1 while col <= row: print ‘%s*%s=%s\t‘ % (col,row,col*row), col += 1 row += 1 print
时间: 2024-11-09 17:08:23