1.左上三角格式:
for i in range(1, 10): # 行 for j in range(1, 10-i+1,): # 列 print('{}x{}={}'.format(i, j, j*i), end='\t') print('\n')
2.左下三角格式:
for i in range(1, 10): for j in range(1, i+1): # print("%d*%d=%2d" % (i, j, i*j), end="\t") # 两种格式,都可以输出 print('{}x{}={}'.format(i, j, i*j), end='\t') print("\n")
3.右上三角格式:
for i in range(1, 10): for k in range(1, i): print(end=" ") for j in range(i, 10): print("%d*%d=%2d" % (i, j, i*j), end=' ') print('\n')
4.右下角格式:
for i in range(1, 10): for k in range(1, 10-i): print(end=" ") for j in range(1, i+1): print("%d*%d=%2d" % (i, j, i*j), end=' ') print('\n')
5.倒三角格式:
for i in range(1, 10): for n in range(1, i): print(end="\t") for j in range(i, 10): # print("%d*%d=%2d" % (i, j, i*j), end="\t") # 两种格式均可 print('{}x{}={}'.format(i, j, i*j), end='\t') print('\n')
上一篇:vscode部署tomcat