2.10.5 Sidewalk Codehs Answers [work] 【8K 2025】
To draw a sidewalk, we first need to know how to draw a single slab.
A function to draw a line of squares helps prevent code repetition. While there are 8 tiles per side, you must account for the corners.
"Write a program that draws a sidewalk. Your sidewalk should have a border on the top and bottom, and vertical lines (the cracks) spaced evenly across the sidewalk." 2.10.5 sidewalk codehs answers
: Define a function to draw a single square, then a function to draw a line of squares. Python Solution Code
Even with the answer above, students often fail the auto-grader. Here is why: To draw a sidewalk, we first need to
add(rect);
A: Check your drawVerticalLine function. The y parameter should be the top border's y , and the height should be bottomY - topY . If you accidentally use height = 200 , the line may overshoot. "Write a program that draws a sidewalk
You might do:
speed(0) # Sets Tracy to the fastest speed # Function to draw a single 50x50 tile def draw_square(): pendown() for i in range(4): forward(50) left(90) penup() forward(50) # Position Tracy at the starting corner penup() setposition(-200, -200) # Draw the sidewalk on all 4 sides for i in range(4): for j in range(8): draw_square() # Turn and reposition at the corner backward(50) left(90) forward(50) Use code with caution. Troubleshooting Common Errors
Using Top-Down Design, we break the problem into three main components: drawing a single square, drawing one full side (a line of squares), and repeating that process for the entire canvas. 1. Drawing a Single Square
# Set the speed to the fastest setting speed(0) # Function to draw a single 50-pixel square def draw_square(): pendown() for i in range(4): forward(50) left(90) penup() forward(50) # Function to draw one full side of the sidewalk (8 squares) def draw_side(): for i in range(8): draw_square() # Turn Tracy 90 degrees to prep for the next side left(90) # Position Tracy at the starting point (bottom-left corner) penup() setposition(-200, -200) # Use a loop to draw all four sides of the sidewalk for i in range(4): draw_side() Use code with caution. Copied to clipboard