From 12286b4e5328f7c55e7c654daf1a6176c3dac0e9 Mon Sep 17 00:00:00 2001 From: Chris Mekelburg Date: Sun, 1 Sep 2024 16:49:29 -0400 Subject: [PATCH] checkpoint 2 drawing with shapes A function is like a variable because it allows something to be repeated over and over again. In this case, the "something" is a set of commands rather than a value. If a function that is called many times needs to be changed, it only needs to be changed once, where the function is defined. Functions help to break down larger problems into smaller problems by breaking down a larger task (such as drawing the complex shapes) into a series of smaller tasks that are repeated. It is then easier to troubleshoot the smaller task before looking at the larger task. Another example would be if you have a block of code to make a robot move, functions for moving forward, reverse, and turning could be repeated over and over again. If the turn is off by a few degrees, the turning function could be adjusted, rather than trying to need to look through the entire code and finding every time the robot turns. --- shapes.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/shapes.py b/shapes.py index 731ec39..c835492 100644 --- a/shapes.py +++ b/shapes.py @@ -5,7 +5,20 @@ from turtle import * def triangle(side_length): - pass + forward(side_length) + right(120) + forward(side_length) + right(120) + forward(side_length) + right(120) def rectangle(height, width): - pass + forward(width) + right(90) + forward(height) + right(90) + forward(width) + right(90) + forward(height) + right(90) +