我在编码方面有点新手,所以我对Python棋盘任务有点困惑。
我想我的代码有点“过度”。在
所以这里有一个任务:
给两个棋盘格。如果它们是用一种颜色画的,请打印“是”,如果是用另一种颜色-否。
程序接收从1到8的四个数字的输入,每个数字指定列和行号,前两个用于第一个单元格,后两个用于第二个单元格。在
我的密码是:h1 = int (input()) #first cell height
w1 = int (input()) #first cell width
h2 = int (input()) #second cell height
w2 = int (input()) #second cell width
#Guessing first cell color
if ((h1 % 2 != 0) and (w1 % 2 != 0)) or ((h1 % 2 == 0) and (w1 % 2 == 0)):
one = str ('black')
else:
one = str ('white')
#Guessing second cell color
if ((h2 % 2 != 0) and (w2 % 2 != 0)) or ((h2 % 2 == 0) and (w2 % 2 == 0)):
two = str ('black')
else:
two = str ('white')
#compare two cells
if one == two:
print ('YES')
else:
print ('NO')
一些东西告诉我,它可以比当前版本简单得多。在