Python Day3 打印三种形式的九九乘法表
作者:互联网
左下
for i in range(1, 10):
for j in range(1, i+1):
print("{0}*{1}={2}".format(i, j, i * j), end = "\t")
print("")
右上
for i in range(1, 10):
for j in range(1, i):
print(end = "\t\t") # 没有end就会自动换行了
for k in range(i, 10):
print(str.format("{}*{}={}", i, k, i * k), end = "\t")
print("")
全部
法一:
for i in range(1, 10):
for j in range(1, 10):
print("{}*{}={}".format(i, j, i * j), end = "\t")
print("")
法二:
for i in range(1, 10):
s = ""
for j in range(1, 10):
s += str.format("{}*{}={:<4}", i, j, i * j)
print(s)
标签:10,九九乘法,end,format,Python,Day3,range,str,print 来源: https://blog.csdn.net/qq_55786319/article/details/123097056