python之九九乘法表

python之九九乘法表,一行一行的打印出来。

for i in range(1,2):
    print( '%d X %d = %d' % (i,1,i*1) ,end = ' ' )
print('') 
for i in range(1,3):
    print( '%d X %d = %d' % (i,2,i*2) ,end = ' ' )
print('') 
for i in range(1,4):
    print( '%d X %d = %d' % (i,3,i*3) ,end = ' ' )
print('') 
for i in range(1,5):
    print( '%d X %d = %d' % (i,4,i*4) ,end = ' ' )
print('')
for i in range(1,6):
    print( '%d X %d = %d' % (i,5,i*5) ,end = ' ' )
print('') 
for i in range(1,7):
    print( '%d X %d = %d' % (i,6,i*6) ,end = ' ' )
print('')
for i in range(1,8):
    print( '%d X %d = %d' % (i,7,i*7) ,end = ' ' )
print('') 
for i in range(1,9):
    print( '%d X %d = %d' % (i,8,i*8) ,end = ' ' )
print('')
for i in range(1,10):
    print( '%d X %d = %d' % (i,9,i*9) ,end = ' ' )
print('')

合并成2层for循环:

for i in range(1,10):
    for j in range(1,i+1):
        print( '%d X %d = %d' % (j,i,i*j),end = ' ' )
    print(' ')

九九乘法表运行结果如下:

未经允许不得转载:不惑博客 » python之九九乘法表

赞 (1) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏