Python 九九乘法表 for、while循环

Python 九九乘法表 for、while循环_第1张图片

# for循环

for h in range(1, 10):
    for l in range(1, h+1):
        mul = h * l
        print("%d*%d=%d"% (h, l, mul), end="\t")
    print()
  
 
# while循环

h = 0
mul = 0  # 乘积
while h <= 9:
    l = 1
    while l <= h:
        mul = h * l
        print("%d*%d=%d"% (h, l, mul), end="\t")
        l += 1
    print()
    h += 1

你可能感兴趣的:(python,算法,python)