本文共 561 字,大约阅读时间需要 1 分钟。
一、第一种for实现(不推荐)
代码:
for j in range(1, 10): #计从1到9,不包括10,而且1-9是连续的range(100)默认0-99 for i in range(1, j+1): #观察发现乘号左边的数字小于等于右边的数字,i左,j右,一般二层循环的变量小于一层的(非通用) result = i * j if i
参考原博客链接:
(2)第二种for实现
代码:
for row in range(1, 10): for col in range(1, row+1): print('{}*{}={}'.format(col, row, col * row), end='\t') print()
二、while实现
代码:
用while实现row = 1while row <10: col = 1 while col <= row: print('{}*{}={}'.format(col, row, col * row), end = '\t')#见for循环的分析 col += 1 print() #换行 row += 1 #内循环结束,外循环加一
转载地址:http://mkwsi.baihongyu.com/