Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. N=input("Give the dimensions(Odd number) => ")
  2. board=[[0]*N for i in range(N)]
  3.  
  4. i=N/2
  5. j=N-1
  6.  
  7.  
  8. for num in range(1,N*N+1):
  9. if(board[i][j]!=0):
  10. i-=1
  11. j-=2
  12.  
  13. if(i<0):
  14. i=N-1
  15. if(j<0):
  16. j=N+j
  17.  
  18.  
  19.  
  20. board[i][j]=num
  21.  
  22. i+=1
  23. j+=1
  24.  
  25. if(i==N):
  26. i=0
  27. if(j==N):
  28. j=0
  29.  
  30.  
  31.  
  32. print "\nSum of each row,collumn and diagonial is calculated from 'N*(N^2+1)/2'\nAnd its value is: %d\n" %(N*(N*N+1)/2)
  33. for i in board:
  34. print "|",
  35. for num in i:
  36. print num,"|",
  37. print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement