# ⽅法1,使⽤while嵌套# j = 0
# while j < 9:# j += 1
# # 内循环控制⾏# i = 0
# while i < j:# i += 1
# print(i, '*', j, '=', (i * j), end=' ')# print()
# ⽅法2,使⽤for语句# for i in range(1, 10):
# for j in range(1, i + 1):
# print('{}x{}={}\'.format(j, i, i * j), end='')# print()
# ⽅法3,使⽤while...for语句# i = 1
# while(i <=9):
# for j in range (1,i+1): #range()函数左闭右开# print('%d*%d=%-3d'%(i,j,i*j),end='')# i += 1# print()
# ⽅法4,使⽤for...while语句# for i in range(1,10):# j = 0
# while j < i:# j += 1
# print(\"%d*%d=%-3d\"%(i,j,i*j),end='')# print( )
# ⽅法5,定义⼀个变量
# a = [1, 2, 3, 4, 5, 6, 7, 8, 9]# for i in a:# j = 1
# while j <= i:
# print('%d*%d=%-3d'%(i,j,i*j),end='\')
# # %-3d 是控制输出结果占据3位,且从左⾯开始对齐# j += 1# print( )
# ⽅法6,使⽤⼀⾏语句
print('\\n'.join([' '.join([\"%2s x%2s = %2s\" % (j, i, i*j) for j in range(1, i+1)]) for i in range(1, 10)]))
因篇幅问题不能全部显示,请点此查看更多更全内容