From 79e763b9e744cf6ea9b6cc80cb60014f0e9954c1 Mon Sep 17 00:00:00 2001 From: njmason2 Date: Sun, 7 Sep 2025 16:05:04 -0400 Subject: [PATCH] square.py I put documentation in my code, explaining each line. I hadn't written code in 12 months, so I had to refresh my previous learning. You have to think logically, unlike computers, which don't think at all! For larger programs, draw a flowchart! --- square.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/square.py b/square.py index f1fb2a2..7a4c5a7 100644 --- a/square.py +++ b/square.py @@ -1,17 +1,21 @@ 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) -sizes = [20, 40, 60, 80, 100] -for size in sizes: - square(size) -input() +sizes = [20, 40, 60, 80, 100] # list +for size in sizes: # outer loop, different square sizes from list + def square(): # function definition + for x in range(0,4): # inner loop creating a square + forward(size) # size doesn't change until the outer loop is executed + right(90) # right turn 90 degrees + + # this code block for the outer loop (below) has to be + # precisely indented in line with the def square(): function definition, + # otherwise it won't run properly + pendown() # same starting point for each square + color('blue') + square() # first calling and drawing of a square side from the inner loop, + # then drawing a different square size from the "for loop" outer loop + penup() + +input() # pause the turtle display screen to see the drawing