# Why is it wrong at one case? (python)

`The goal is to tell whether can the king go to the cell or not. `
```a=int(input())
b=int(input())
c=int(input())
d=int(input())
n= abs (a-c)
m= abs (b-d)
if n==m==1:
print('YES')
elif a==c and b+1==d or d+1==b:
print('YES')
elif b==d and a+1==c or c+1==a:
print('YES')
else:
print('NO')```

+1 vote
answered Dec 17, 2021 by (55,660 points)
edited Dec 17, 2021 by Peter Minarik

I don't see what the problem would be with your program. It seems to me it works fine. Could you provide an input where it does not work as expected?

Also, it is a good idea to have a proper problem description. E.g. This is a chess problem. We would like to see if the king chess piece can move from one cell to another. Both coordinates of the start and end cells are indexed by numbers.

I've changed your code a bit, made the user input more talkative and changed the variable names to more meaningful ones. Added some comments and simplified the check if the destination (end) cell is right next to the king's current location, i.e. their relative distance (offset) from one another is no more than 1 cell in either direction:

```# User input
startX = int(input('startX: '))
startY = int(input('startY: '))
endX = int(input('endX: '))
endY = int(input('endY: '))
# Decision making
offsetX = abs(startX - endX)
offsetY = abs(startY - endY)
if (offsetX <= 1 and offsetY <= 1):
print('YES')
else:
print('NO')```

commented Jan 26 by (100 points)
a = int(input())

b = int(input())

c = int(input())

d = int(input())

n = abs (a-c)

m = abs (b-d)

if n == m == 1:
print("YES")

elif a == c and b + 1 == d or d + 1 == b:
print("YES")

elif b == d and a + 1 == c or c + 1 == a:
print("YES")

else:
print("NO")