码迷,mamicode.com
首页 > 其他好文 > 详细

99乘法表的四种位置类型for...in while

时间:2017-11-12 20:11:56      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:bsp   乘法   end   nbsp   --   +=   乘法表   for   位置   

#whlie循环

#方向一(左下角)
i = 1
while i<=9:
  j=1
  while j<=i:
    print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
    j+=1
  print()
  i+=1

print(‘----------------------------------------------------‘)

#方向二(右下角)
i = 1
while i<=9:
  k=1
  while k<=9-i:
    print(‘ ‘,end=‘‘)
    k+=1
  j=1
  while j<=i:
    print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
    j+=1
  print()
  i+=1

print(‘---------------------------------------------------‘)
#方向三(左上角)
i = 9
while i>=1:
  j=1
  while j<=i:
    print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
    j+=1
  print()
  i-=1

print(‘---------------------------------------------------‘) 

#方向四(右下角)
i = 9
while i>=1:
  k=1
  while k<=9-i:
    print(‘ ‘,end=‘‘)
    k+=1
  j=1
  while j<=i:
    print("%d*%d=%2d "%(i,j,i*j),end=‘‘)
    j+=1
  print()
  i-=1

#  for...in循环

# 方向一(左下角)

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

print(‘---------------------------------------------------------‘)

#方向二(左上角)
for i in range(1,10):
  for j in range(i,10):
    print(‘%d*%d=%2d ‘ %(i,j,i*j),end = ‘‘)
  print()

print(‘-----------------------------------------------------‘)

#方向三(右下角)

for i in range(1,10):
  for k in range(i,9):
    print(end = ‘ ‘)
  for j in range(1,i+1):
    print(‘%d*%d=%2d ‘ %(i,j,i*j),end = ‘‘)
  print()

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()

 

99乘法表的四种位置类型for...in while

标签:bsp   乘法   end   nbsp   --   +=   乘法表   for   位置   

原文地址:http://www.cnblogs.com/sihulu/p/7822629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!