Answer the question
In order to leave comments, you need to log in
How to create a (chessboard) matrix in Python?
Task: Set the coordinates of two chess fields and display the same color or not.
Input - 1122 Output - yes
I tried to solve it like this (in the code, do not hit: 95% of qbasik knowledge, the rest is "sugar" from python):
m = [[0] * 8] * 8
md = ['Черный','Белый']
n = 0
for i in range(8):
for r in range(8):
if n == 0:
while n < 1:
m[i][r] = md[n]
n += 1
else:
while n >= 1:
m[i][r] = md[n]
n -= 1
v = input('Введите координаты полей')
if m[int(v[0])][int(v[1])] == m[int(v[2])][int(v[3])]:
print('Yes')
else:
print('No')
Answer the question
In order to leave comments, you need to log in
It's not about the language, it's about the algorithm. You have a complete bust here, which is not needed.
def chess(a,b):
return ((a[0]+a[1])&1 == (b[0]+b[1])&1);
print 'yes' if chess((1,2),(0,2)) else 'no';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question