版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011466469/article/details/88874508
需求:使用python语言的while和for循环分别打印输出九九乘法表。
# 九九乘法表一:
# range方法,左闭右开
for i in range(1, 10):
for j in range(1, i + 1):
print("{}x{}={}\t".format(i, j, i * j), end="")
print(" ")
# 九九乘法表二:
i = 1
while i <= 9:
j = 1
while j <= i:
print("%d*%d=%2d" % (i, j, i * j), end=" ")
j += 1
print()
i += 1
p'ython的格式化输出需要注意,可以不同方式的格式化输出。