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.18.4 Increasing 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()
length = 50
Draws a square
def squarez():
for i in range(4):
forward(length)
left(90)
Draws concentric squares after repositioning
while length < 400:
left(90)
forward(length / 2)
right(90)
forward(length / 2)
left(180)
pendown()
squarez()
penup()
setposition(0,0)
length = length + 50

This code snippet aims to draw a series of increasing squares, starting from a certain size and increasing the side length incrementally until it reaches a maximum value.

However, there are a few issues with the structure and logic of the code, particularly with the placement of the loop and function definition.

Here’s a revised version that correctly implements the idea:

import turtle

turtle.speed(0)  # Set the drawing speed to the fastest

# Function to draw a square of a given length
def squarez(length):
    for _ in range(4):
        turtle.forward(length)
        turtle.left(90)

# Initial length of the square
length = 50

# Loop to draw concentric squares, increasing the size each time
while length <= 400:
    # Reposition the turtle to the bottom-left corner of the next square
    turtle.penup()
    turtle.goto(-length / 2, -length / 2)
    turtle.pendown()
    
    # Draw the square
    squarez(length)
    
    # Increase the length for the next square
    length += 50

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

This corrected version works as follows:

  1. Function Definition (squarez): Defines a function that draws a square of a specific length. This function is called within the loop with different lengths to draw each square.
  2. Initial Length: Sets the initial side length of the first square to 50 units.
  3. Loop: Uses a while loop to draw squares with increasing side lengths. Before drawing each square, it moves the turtle to what will be the bottom-left corner of the square, ensuring that all squares are centered around the same point on the screen. This is achieved by using the turtle.goto function with coordinates that offset the turtle by half the length of the square’s side in both the x and y directions.
  4. Increment Length: After each square is drawn, increases the side length by 50 units for the next square, continuing until the side length reaches 400 units.

By adjusting the starting position before each square is drawn, this code effectively creates a pattern of increasing squares, centered around the same point.

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