Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Write your code here
- def get_dimension():
- try:
- print("Enter the knight's starting position:")
- x = input()
- if [z.isdigit() for z in x]:
- x = x.split()
- # print(x)
- x = [int(i) for i in x]
- # print(x)
- if len(x) == 2:
- if 0 < x[0] < 9 and 0 < x[1] < 9:
- print_board(x[0], x[1])
- else:
- raise ValueError
- else:
- raise ValueError
- else:
- raise ValueError
- except ValueError:
- print('Invalid dimensions!')
- def print_board(m, n):
- print(' -------------------')
- r = 8
- c = 8 + 3
- mat = [['_' for x in range(c)] for y in range(r)]
- for y in range(r):
- mat[y][0] = r - y
- mat[y][1] = '|'
- mat[y][c - 1] = '|'
- mat[8 - n][m - 1 + 2] = 'X'
- for i in range(r):
- for j in range(c):
- print(mat[i][j], end=" ")
- print()
- print(' -------------------\n 1 2 3 4 5 6 7 8')
- get_dimension()
Add Comment
Please, Sign In to add comment