#打印九九乘法表 for i in range(1,10):
s = ""
for j in range(1,i+1):
s += str(j) + '*' + str(i) + '=' + str(i*j)+ ' '
print(s)
方法2:
#打印九九乘法表 for i in range(1,10):
for j in range(1,i+1):
print('{}*{}={}\t'.format(j,i,i*j),end="")
print()
方法3(将打印的结果对齐):
#打印九九乘法表,并将结果行、列对齐 for i in range(1,10):
for j in range(1,i+1):
product = i*j
if j>1 and product<10:
product = str(product) + ' '
else:
product = str(product)
print(str(j)+'*'+str(i)+"="+product,end=' ')
print()
方法4(将打印的结果对齐):
#打印九九乘法表,并将结果行、列对齐 for i in range(1,10):
line = ' '
for j in range(1,i+1):
line += '{}*{}={:<2} '.format(j,i,i*j)
print(line)