MeowalsoMeow

knights_tour_stage1

Jun 24th, 2021 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. # Write your code here
  2. def get_dimension():
  3. try:
  4. print("Enter the knight's starting position:")
  5. x = input()
  6. if [z.isdigit() for z in x]:
  7. x = x.split()
  8. # print(x)
  9. x = [int(i) for i in x]
  10. # print(x)
  11. if len(x) == 2:
  12. if 0 < x[0] < 9 and 0 < x[1] < 9:
  13. print_board(x[0], x[1])
  14. else:
  15. raise ValueError
  16. else:
  17. raise ValueError
  18. else:
  19. raise ValueError
  20. except ValueError:
  21. print('Invalid dimensions!')
  22.  
  23.  
  24. def print_board(m, n):
  25. print(' -------------------')
  26. r = 8
  27. c = 8 + 3
  28. mat = [['_' for x in range(c)] for y in range(r)]
  29. for y in range(r):
  30. mat[y][0] = r - y
  31. mat[y][1] = '|'
  32. mat[y][c - 1] = '|'
  33.  
  34. mat[8 - n][m - 1 + 2] = 'X'
  35. for i in range(r):
  36. for j in range(c):
  37. print(mat[i][j], end=" ")
  38. print()
  39. print(' -------------------\n 1 2 3 4 5 6 7 8')
  40.  
  41.  
  42.  
  43.  
  44. get_dimension()
  45.  
  46.  
  47.  
Add Comment
Please, Sign In to add comment