I changed the four original lines of making squares into a loop of four squares, shortening the code.

No it was not difficult to figure out how to rewrite square using a for-loop. The strategy I used was; instead of repeating forward and right multiple times, I told the program to space out the squares and draw 5 of them.
This commit is contained in:
jbayati
2025-09-26 09:31:48 -04:00
parent cb49c1a734
commit 0c57f896fd

View File

@@ -1,17 +1,16 @@
from turtle import *
def square(side_length):
forward(side_length)
right(90)
forward(side_length)
right(90)
forward(side_length)
right(90)
forward(side_length)
right(90)
for i in range (4):
forward(side_length)
right(90)
sizes = [20, 40, 60, 80, 100]
for size in sizes:
square(size)
square(20)
penup()
forward(40)
pendown()
input()