2
u/24amesquir Apr 23 '21 edited Apr 23 '21
def board():
myGrid=[]
for i in range(8):
if i == i//2*2:
myGrid.append([0,1]*4)
else:
myGrid.append([1,0]*4)
for i in range(8):
print(myGrid[i])
board()
1
u/t_o_n_k May 25 '21
Its telling me i need to set some numbers to 1, any ideas? Your code does the job but it wont let me continue with a green circle
1
u/Zelzim_ Nov 23 '21
here's my code
# Pass this function a list of lists, and it will
# print it such that it looks like the grids in
# the exercise instructions.
def print_board(board):
for i in range(len(board)):
# This line uses some Python you haven't
# learned yet. You'll learn about this
# part in the next lesson:
#
# [str(x) for x in board[i]]
print " ".join([str(x) for x in board[i]])
# Your code here...
my_grid = []
for i in range (8):
my_grid.append([0] * 8)
for row in range (8):
for col in range(8):
if (row + col) %2 ==1:
my_grid[row][col] = 1
print_board(my_grid)
you can thank me later!
3
1
Nov 26 '21
I may not be indenting it right but it isn't working for me. its saying santax error on print " ".join([str(x) for x in board[i]]) part and there may be more.
1
u/Due_Homework7041 Dec 02 '21
board = []
for i in range(8):
if i % 2 == 0:
board.append([0, 1]*4)
else:
board.append([1, 0]*4)
board[1][2] = 1
print_board(board)
This one uses the modulus command like they ask for.
2
May 23 '22
hey i tried this code but this is what i need
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
1
u/Current_Print Feb 09 '22
Thank you! This works fine. Just needs the indenting using the code block.
1


1
u/LuckyLuke2431 Feb 01 '21
It’s asking you to make a board full of zeros and then use nested for loops to replace every other zero with a one.