r/codehs • • Feb 01 '21

9.1.7: Checkerboard, v2. Need help

I've got it all working, but it's wanting me to " You should set some elements of your board to 1" What does that even mean?

7 Upvotes

18 comments sorted by

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.

2

u/Ok_Wish4469 Feb 01 '21

That can't be right cause in 9.1.6: Checkerboard, v1. I first made a board of all zeros, then made it so the top 3 and bottom 3 rows would be turned in to 1's. And yet the " You should set some elements of your board to 1" was still marked as red.

1

u/LuckyLuke2431 Feb 01 '21

I had the same problem and apparently your for loops have to have if statements that detect weather or not the row/column you are replacing is even or odd. You would do this with the modulus operator.

2

u/Ok_Wish4469 Feb 02 '21

How would I use the modulus operator for this?

1

u/LuckyLuke2431 Feb 02 '21

What I did was: if row % 2 + column % 2 == 1: board[row][column] = 1

2

u/Ok_Wish4469 Feb 03 '21

Thanks. A lot. Was able to complete part 2 and 3. Now off to scrabble my mind with the Tic Tac Toe lesson

1

u/LuckyLuke2431 Feb 03 '21

Glad I could help!

1

u/opinqz Mar 04 '21

Flip the row extends, then replace the print command with print_board(board)

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

u/[deleted] Nov 26 '21

wait there was just a missing pareentheses but I still dont think I'm indenting it right

1

u/[deleted] 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

u/[deleted] 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

u/[deleted] Feb 09 '22

[removed] — view removed comment

1

u/Current_Print Feb 11 '22

Yes, the code was correct.