1.使用while循环
# while循环实现乘法口诀表
i = 1
while i < 10:
j = 1
while j <= i:
print("%d * %d = %d " % (j, i, i*j), end="") # end = ""保证每一行输出不换行
if j == i:
print("") # 每一行输出最后一组乘法时换行
j = j + 1
i = i + 1
2.for循环实现
# for循环实现乘法口诀表
for i in range(1, 10):
for j in range(1, i+1):
print("%d * %d = %d " % (j, i, i * j), end="") # end = ""保证每一行输出不换行
if j == i:
print("") # 每一行输出最后一组乘法时换行
j = j + 1
i = i + 1