黑马程序员技术交流社区

标题: 循环训练之九九乘法表(九种打印方法) [打印本页]

作者: Arthur-Qu    时间: 2019-10-28 15:57
标题: 循环训练之九九乘法表(九种打印方法)
# 九九乘法表1
j = 0
while j < 9:
    j += 1
    i = 0
    while i < j:
        i += 1
        print("%d * %d = %d" % (i,j,i*j),end="\t")
    print()

print("-"*100)

# 九九乘法表2
j = 10
while j >0:
    j -= 1
    i = 0
    while i < j:
        i += 1
        print("%d * %d = %2d" % (i,j,i*j),end=" ")
    print()

print("-"*100)

# 九九乘法表3
j = 9
while j >0:
    i = 9
    while i >= j:
        print("%d * %d = %2d" % (i,j,i*j),end=" ")
        i -= 1
    print()
    j -= 1



print("-"*100)

# 九九乘法表4
j = 0
while j < 9:
    j += 1
    print(" " * 11 * (9 - j), end="")
    i = j
    while i > 0:
        print("%d * %d = %2d" % (i,j,i*j),end=" ")
        i -= 1
    print()



print("-"*100)

# 九九乘法表5
j = 10
while j >0:
    j -= 1
    i = j
    print(" " * 11 * (9 - j), end="")
    while i > 0:
        print("%d * %d = %2d" % (i,j,i*j),end=" ")
        i -= 1
    print()

print("-"*100)

# 九九乘法表6
for i in range(1, 10):
    for j in range(1, i + 1):
        print(f"{i} * {j} = {i*j}", end="\t")
    print()

print("-"*100)

# 九九乘法表7
for i in range(9, 0, -1):
    for q in range(1, i + 1):
        print(f"{i} * {q} = {i*q}", end="\t")
    print()


print("-"*100)

# 九九乘法表8
for i in range(1, 10):
    print(" " * 11 * (9 - i), end="")
    for j in range(1, i + 1):
        print("%d * %d = %2d" % (i, j, i * j), end=" ")
    print()

print("-"*100)

# 九九乘法表9
for i in range(9,0,-1):
    print(" " * 11 * (9 - i), end="")
    for j in range(1, i + 1):
        print("%d * %d = %2d" % (i, j, i * j), end=" ")
    print()






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2