THIS PYTHON PROGRAMMING
On a chessboard, positions are marked with letters between a and h for the column and a number between 1 and 8 for the row. The first place on the board, a1, is black. The next is white, alternating across a row. Odd rows start with black, even rows start with white. Given a 2 character input string with a letter (a-h) and a number (1-8), print "Black" or "White" indicating if the square is black or white. Use if-else statements only. Can you also explain how you got the code?
Pleae give thumbs up, thanks
code:
inp=input("Enter Board Poition : ");
col=int(ord(inp[0])-ord('a'));
row=int(ord(inp[1])-ord('1'));
if(col%2==0 and row %2==0) or (col%2==1 and row %2==1):
print("Black");
else:
print("White");
Get Answers For Free
Most questions answered within 1 hours.