python实现NN乘法表打印

九九乘法表实现如下:

i = 1
while i <= 9:
    j = 1
    while j <= i:
        print("%d * %d = %d" % (j, i, i*j), end="\t")
        j += 1
    print("")
    i += 1

通过将行数使用变量替代行数参数即可实现NN乘法表:

i = 1
num = int(input("请输入需要打印的行数"))
while i <= num:
    j = 1
    while j <= i:
        print("%d * %d = %d" % (j, i, i*j), end="\t")
        j += 1
    print("")
    i += 1

猜你喜欢

转载自blog.csdn.net/weixin_44594056/article/details/89202263