Repository navigation
Expand file tree
/
Copy pathfinal_code2.py
More file actions
54 lines (54 loc) · 2.41 KB
/
Copy pathfinal_code2.py
File metadata and controls
54 lines (54 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def final_code(param1, param2, param3, param4, param5, param6, param7):
letters = 'abcdefgh'
knight_hor = param1.lower()
i = 0
if i < 10:
x = param2
i += 1
if i < 10:
x = param3
i += 1
if i < 10:
x = param4
i += 1
assert i < 10
if len(knight_hor) != 1 or not knight_hor.isalpha():
print('Horizontal input for knight is not a letter')
elif knight_hor not in letters:
print('Horizontal input for knight is not a proper letter')
else:
knight_column = param5
if not knight_column.isdigit():
print('Vertical input for knight is not a number')
else:
knight_column = knight_column
if knight_column < 1 or knight_column > 8:
print('Vertical input for knight is not a proper number')
else:
bishop_hor = param6.lower()
if len(bishop_hor) != 1 or not bishop_hor.isalpha():
print('Horizontal input for bishop is not a letter')
elif bishop_hor not in letters:
print('Horizontal input for bishop is not a proper letter')
else:
bishop_column = param7
if not bishop_column.isdigit():
print('Vertical input for bishop is not a number')
else:
bishop_column = bishop_column
if bishop_column < 1 or bishop_column > 8:
print(
'Vertical input for bishop is not a proper number'
)
else:
row_dif = abs(letters.index(knight_hor) -
letters.index(bishop_hor))
hor_dif = abs(knight_column - bishop_column)
if row_dif == 0 and hor_dif == 0:
print("They can't be in the same square")
elif row_dif != 0 and hor_dif != 0 and row_dif + hor_dif == 3:
print('Knight can attack bishop')
elif row_dif == hor_dif:
print('Bishop can attack knight')
else:
print('Neither of them can attack each other')