python打印九九乘法表的菱形实现

Python105
1 NUM = 9
 2 for i in range(1, NUM+1):
 3     print()
 4     for j in range(1, i+1):
 5         if j == 1:
 6             print(5*(NUM-i)*(" "), end="")
 7         print("{0} * {1} = {2} ".format(j, i, i*j), end="")
 8
 9 for i in range(NUM-1, 0, -1):
10     print()
11     for j in range(1, i+1):
12         if j == 1:
13             print(5*(NUM-i)*(" "), end="")
14         print("{0} * {1} = {2} ".format(j, i, i*j), end="")
15
16

效果如图:

输入验证码查看隐藏内容

扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长