Give the position of 8 queens on the chessboard. Print YES if at least one pair of queens hit each other. If not print out NO.
so here's my code but when checking if these queens can hit ea other diagonally, python says
unsupported operand type(s) for Sub: "str" and "str"
a, b = input().split()
c, d = input().split()
e, f = input().split()
g, h = input().split()
i, j = input().split()
k, l = input().split()
m, n = input().split()
o, p = input().split()
#check cross or straight
if a==c or c==e or e==g or g==i or i==k or k==m or m==o or o==a or b==d or d==f or f==h or h==j or j==l or l==n or n==p or p==b:
print("YES")
#check diagonally
elif a==b and c==d or c==d and e==f or e==f and g==h or g==h and i==j or i==j and k==l or k==l and a==b:
print("YES")
elif abs(int(a-b))==abs(int(c-d)) or abs(int(c-d))==abs(int(e-f)) or abs(int(e-f))==abs(int(g-h)) or abs(int(g-h))==abs(int(i-j)) or abs(int(i-j)) == abs(int(k-l)) or abs(int(k-l))==abs(int(a-b)):
print("YES")
else:
print("NO")
these inputs are splited by spaces (coordination of each queen on the chess board)
example coordination
1 3
4 8
6 1
5 5
2 7
8 6
7 4
3 2
So you'll basically convert everything into a list so it will be easier to check
rows = []
cols = []
for _ in range(8):
r, c = [int(v) for v in input().split()]
rows.append(r)
cols.append(c)
count = 0
for i in range(8):
for j in range(i+1, 8):
if rows[i] == rows[j] or cols[i]==cols[j] or abs(rows[i]-rows[j])==abs(cols[i]-cols[j]):
count += 1
if count==0:
print("NO")
else:
print("YES")