fork download
  1. n = int(input('Input an integer(from 1 to 10, inclusive): '))
  2. N = 2*n+1
  3. a = [ [ 0 for _ in range(N) ] for _ in range(N) ]
  4. r, c, now = 0, n, 1
  5. while now <= N*N:
  6. a[r][c] = now
  7. if now % N == 0:
  8. r = (r + 1) % N
  9. else:
  10. r -= 1
  11. c = (c + 1) % N
  12. now += 1
  13. for r in range(N):
  14. for c in range(N):
  15. print('%4d' % a[r][c], end="")
  16. print()
Success #stdin #stdout 0.05s 9568KB
stdin
3
stdout
Input an integer(from 1 to 10, inclusive):   30  39  48   1  10  19  28
  38  47   7   9  18  27  29
  46   6   8  17  26  35  37
   5  14  16  25  34  36  45
  13  15  24  33  42  44   4
  21  23  32  41  43   3  12
  22  31  40  49   2  11  20