`

Numeric Diamonds

阅读更多

打印数字菱形:

 

 

  1
 4 2
7 5 3
 8 6
  9
           1
         7   2
      13   8   3
    19  14   9   4
  25  20  15  10   5
31  26  21  16  11   6
  32  27  22  17  12
    33  28  23  18
      34  29  24
        35  30
          36
                             1
                         11     2
                      21    12     3
                   31    22    13     4
                41    32    23    14     5
             51    42    33    24    15     6
          61    52    43    34    25    16     7
       71    62    53    44    35    26    17     8
    81    72    63    54    45    36    27    18     9
 91    82    73    64    55    46    37    28    19    10
    92    83    74    65    56    47    38    29    20
       93    84    75    66    57    48    39    30
          94    85    76    67    58    49    40
             95    86    77    68    59    50
                96    87    78    69    60
                   97    88    79    70
                      98    89    80
                         99    90
                           100

 

分享到:
评论
1 楼 lampeter123 2009-08-25  
def p(n,a):
 for i in range(1,2*n):
  s="";p=" "*a
  if i<=n:    
   for j in range(n-i):
    s=s+p
   for j in range(i):
    g=str(n*i-(n-1)*(j+1))
    if a==1:s=s+g+p
    if a==2:s=s+"%2s"%g+p
    if a==3:s=s+"%3s"%g+p
   print s.rstrip()
  else:
   for j in range(i-n):
    s=s+p
   for j in range(2*n-i):
    h=str((n-1)*(n-1)+i-(n-1)*j)
    if a==1 or a==2:s=s+h+p
    if a==3:s=s+"%3s"%h+p
   print s.rstrip()
p(3,1);p(6,2);p(10,3)

相关推荐

Global site tag (gtag.js) - Google Analytics