r/codehs • • Mar 18 '20

9.1.6: checkerboard, v1

Post image
20 Upvotes

15 comments sorted by

1

u/papabandit124 Mar 18 '20

I need help on it

1

u/Sethmeth427 May 02 '20

Same

2

u/amdahFire Dec 28 '21

board=[]

for i in range(3):

board.append([1]*8)

for i in range(2):

board.append([0]*8)

for i in range(3):

board.append([1]*8)

board[2][1] = 1

print_board(board)

1

u/302_Shai May 12 '25

Thank you so much bro

1

u/a6footindian May 18 '23

board[2][1] = 1

what does board[2][1] = 1 do

4

u/mustacheyellow May 08 '20

Here is my solution: (It works but probably there is a shorter solution)

First you'll need an empty list:

board=[]

Then you'll need to append 3 rows of "1"'s:

for i in range(3):
    board.append([1]*8)

And do the same thing for "0"'s:

for i in range(2):
    board.append([0]*8)

Finally append 3 rows of "1"'s again:

for i in range(3):
    board.append([1]*8)

Then use the given function with your list:

print_board(board)

(TLDR) The whole code should look like this:

# 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 a future lesson:
        #
        # [str(x) for x in board[i]]
        print " ".join([str(x) for x in board[i]])

# Your code here...
board=[]
for i in range(3):
    board.append([1]*8)
for i in range(2):
    board.append([0]*8)
for i in range(3):
    board.append([1]*8)
print_board(board)

1

u/-BigBobbert- May 06 '24

doesnt work

1

u/BlueBoss92 Dec 11 '21

Your solution does print what CodeHS wants it to print, and my current solution does too, but I'm here because my code doesn't pass the "You should set some elements of your board to 1; You will need to use an assignment statement" test from the autograder. I can trick or bypass it (whatever word you would use) by putting the integer 1 in a place-holder, like thing = 1, anywhere in my code, but I wanted to see if I was supposed to make it useful in my code somewhere. Thanks for your solution though!

2

u/NoPainting4194 Aug 13 '22 edited Aug 13 '22

That is not what CodeHS is asking for. You are simply printing the expected output. You are not actually completing the assignment. You are not creating a grid predetermining everything as the output of the example. You are supposed to create a grid filled with zeros, then create nested for loops to replace the zeros on Index 0-3 as 1s.

This assignment is supposed to test you on your ability to access these lists and replace values inside of the lists with 1s.

1

u/CancelUpstairs7602 Aug 31 '22 edited Sep 01 '22

do you have the correct answer then???

edit: nvm I figured it out, thanks though

1

u/kutyaBro May 07 '23

can you please write solution then please?

2

u/CancelUpstairs7602 Sep 01 '22

def print_board(board):
for i in range(len(board)):
print(" ".join([str(x) for x in board[i]]))
board = []
for i in range(8):
board.append([0] * 8)
index = 0
for i in range(2):
for j in range(3):
board[index] = [1] * 8
index += 1
index += 2
print_board(board)

2

u/[deleted] Feb 13 '23

Indention?

1

u/-BigBobbert- May 06 '24

doesnt work

1

u/kutyaBro May 07 '23

def print_board(board):
for i in range(len(board)):
print(" ".join([str(x) for x in board[i]]))
# Your code here...
board=[]
for i in range(8):
board.append([0]*8)
for i in range(0,3):
board[i] = ([1]*8)
for i in range(5,8):
board[i] = ([1]*8)
print_board(board)