【问题标题】:Write a program to print multiplication table pattern in given image编写程序在给定图像中打印乘法表模式
【发布时间】:2023-02-05 23:09:56
【问题描述】:
标签:
python
python-3.x
loops
nested
right-to-left
【解决方案1】:
一行版
print('
'.join(' '.join(str(i*n) for n in range(1,i+1)) for i in range(1,9)))
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
扩展版
for i in range(1,9):
print(' '.join(str(i*n) for n in range(1,i+1)))
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
初级版
for i in range(1,9):
for j in range(1,i+1):
print(i*j," ",end="")
print()
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64