【问题标题】:Write a program to print multiplication table pattern in given image编写程序在给定图像中打印乘法表模式
【发布时间】:2023-02-05 23:09:56
【问题描述】:

For more info please open the picture

我试图打印乘法表,但我希望根据给定的问题图像打印该表。enter image description here

【问题讨论】:

标签: 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

【讨论】:

    猜你喜欢
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 2022-08-02
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多