Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

You must login to ask a question.

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Quizzma Latest Articles

2.16.5 Black and White Squares CodeHS Answers

We thoroughly check each answer to a question to provide you with the most correct answers. Found a mistake? Tell us about it through the REPORT button at the bottom of the page. Ctrl+F (Cmd+F) will help you a lot when searching through such a large set of questions.

The most common answer is:

speed(0)
penup()
setposition(-150,0)
pendown()
def square_lol(even):
if even % 2 == 0:
color(“black”)
begin_fill()
for i in range (4):
forward(25)
left(90)
end_fill()
for i in range(6):
pendown()
square_lol(i)
penup()
forward(40)

To draw a sequence of black and white squares based on their position (even or odd), this function square_lol should fill the square with black color for even positions and presumably leave it unfilled or fill with white for odd positions.

However, the handling for odd positions (to make squares white or unfilled) is missing in your code. Additionally, there are minor syntax issues with your string literals and the placement of turtle movement commands.

Let’s correct and complete your code:

import turtle

turtle.speed(0)  # Set the drawing speed to the fastest
turtle.penup()
turtle.setposition(-150, 0)
turtle.pendown()

def square_lol(even):
    # Fill with black for even, white for odd positions
    if even % 2 == 0:
        turtle.color("black")
    else:
        turtle.color("white")  # Assuming a white background, this will make odd squares appear unfilled
    turtle.begin_fill()
    for _ in range(4):
        turtle.forward(25)  # Side length of the square
        turtle.left(90)
    turtle.end_fill()

# Draw 6 squares in a row, alternating colors
for i in range(6):
    turtle.pendown()
    square_lol(i)
    turtle.penup()
    turtle.forward(30)  # Adjust spacing between squares if necessary

turtle.done()  # Keep the window open until manually closed

This corrected version includes a few adjustments:

  • The square_lol function now checks if the index even is actually even or odd and sets the color accordingly. For even indices, it sets the color to black, and for odd indices, to white.
  • After drawing each square, the turtle moves forward by 30 units to position itself for the next square, ensuring there’s a small gap between each square.
  • The loop correctly iterates 6 times to create 6 squares in a row, with the square_lol function being called with each iteration’s index to determine the square’s color.
  • Import statement for turtle is added at the beginning for completeness.

Was this helpful?




Quizzma Team

Quizzma Team

The Quizzma Team is a collective of experienced educators, subject matter experts, and content developers dedicated to providing accurate and high-quality educational resources. With a diverse range of expertise across various subjects, the team collaboratively reviews, creates, and publishes content to aid in learning and self-assessment.
Each piece of content undergoes a rigorous review process to ensure accuracy, relevance, and clarity. The Quizzma Team is committed to fostering a conducive learning environment for individuals and continually strives to provide reliable and valuable educational resources on a wide array of topics. Through collaborative effort and a shared passion for education, the Quizzma Team aims to contribute positively to the broader learning community.

Related Posts

Leave a comment