# 九九乘法表# 方法一# for i in range(1, 10):# for j in range(1, i+1):# print(‘{}x{}={}\t‘.format(i, j, i*j), end=‘‘)# print() # 方法二、# print (‘\n‘.join([‘ ‘.join([‘%s*%s=%-2s‘ % (j,i,i*j) for j in range(1,i+1)]) for i in range(1,10)]))## 方法三、# print(‘\n‘.join(‘ ‘.join([‘{}*{}={}‘.format(i,j,i*j) for i in range(1,j+1)])# for j in range(1,10))) # 方法四 长方形完整格式输出九九乘法表# for i in range(1,10):# for j in range(1,10):# print("%d*%d=%2d" % (i,j,i*j),end=" ")# print("") # 方法五 左上三角格式输出九九乘法表# for i in range(1,10):# for j in range(i,10):# print("%d*%d=%2d" % (i,j,i*j),end=" ")# print("") # 方法六 右上三角格式输出九九乘法表# 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("") # 方法七 右下三角格式输出九九乘法表# for i in range(1,10):# for k in range(1,10-i):# print(end=" ")# for j in range(1,i+1):# product=i*j# print("%d*%d=%2d" % (i,j,product),end=" ")# print (" ") #方法八 while循环
i=1while i<=9: j=1 while j<=i: print("%d*%d=%-2d"%(i,j,i*j),end=‘\t‘) j+=1 print(‘\n‘) i+=1
原文地址:https://www.cnblogs.com/jackzz/p/9125233.html
时间: 2024-11-07 22:55:30