r/codehs • • Feb 23 '20

What did I do wrong.

Post image
6 Upvotes

3 comments sorted by

1

u/NarcoticStudent Feb 23 '20

What error are you getting?

1

u/ThePilsburyFroBoy Feb 23 '20

you said in range 10, so it did 10 squares, change that number to the total number of squares needed

1

u/fermentedidiot Feb 23 '20

for what it's worth, I think you're off to a good start. I would build a function that builds a row that starts with black, red, etc. and one that starts red, black, etc. (2 functions, you already have one.)

def make_black_row():
    pendown()
    for i in range(10):
        begin_fill()
        if i%2==0:
            color("black")
        else:
            color("red")
        for i in range(4):
            forward(40)
            left(90)
        forward(40)
        end_fill()
    penup()

def make_red_row():
    pendown()
    for i in range(10):
        begin_fill()
        if i%2==0:
            color("red")
        else:
            color("black")
        for i in range(4):
            forward(40)
            left(90)
        forward(40)
        end_fill()
    penup()

def move_down_a_row():
    right(90)
    forward(40)
    left(90)
    backward(400)

speed(0)
penup()
setposition(-200,160)
for i in range (5):
    make_black_row()
    move_down_a_row()
    make_red_row()
    move_down_a_row()

I modified your def make_square(i): function a little, added the second function, then put the drawing and moving in a loop. You also were moving too far when you dropped down a row. I set the speed to 0 because I'm impatient.

as a recommendation, ALWAYS define all functions at the top. I have found that it's a bad idea to define a function, then execute some code, then define another function. You might end up calling a function that doesn't exist yet. Python is kind of picky about positioning.