40.1k views
2 votes
Write a Python program that makes a turtle draw the shape below, which consists of 8 squares in a row:

1 Answer

1 vote

Answer:

import turtle

window = turtle.Screen()

turtle.speed(0)

turtle.pensize(5)

def draw_square():

times_drawn = 0

# position on the 'x' access.

x = -350

# while the amount of times drawn is less than or equal to 8 the square gets drawn.

while times_drawn <= 8:

# increases the 'x' value by 75.

x += 75

times_drawn += 1

turtle.penup()

turtle.goto(x, 0)

turtle.pendown()

turtle.color("black")

# for loop that draws the square.

for i in range(4):

turtle.forward(50)

turtle.left(90)

turtle.penup()

draw_square()

turtle.done()

Step-by-step explanation:

User Andrey Bienkowski
by
6.0k points