signed

QiShunwang

“诚信为本、客户至上”

Python——利用循环语句打印九九乘法表

2021/3/21 9:54:03   来源:

Python——利用循环语句打印九九乘法表

for循环实现

for i in range(1, 10):
    for j in range(1, i + 1):
            print("{} x {} = {:<2}  ".format(j, i, i * j), end='')
    print()

双层while循环实现

i = 1
while i < 10:
    j = 1
    while j <= i:
        print("{} x {} = {:<2}  ".format(j, i, i * j), end='')
        j += 1
    i += 1
    print()

单层while循环实现

i = 0
j = 1
while j < 10:
    i += 1
    print("{} x {} = {:<2}  ".format(i, j, i * j), end='')
    if(i == j):
        print()
        i = 0
        j += 1