Files
lab_names/shapes.py
erbrown 4bb63d1c33 In the function section of def triangle I added:
forward(side_length) and right(120) three times
In the function section of def rectangle I added:
forward(height) and forward(width) two times and right(90) four times

Checkpoint 2: A function is like a variable by assigning a value to it. When we made the function of triangle we have one parameter where we set it to be side_lenth of the triangle just like how if we have a variable we set it to refer to soemthing. Functions can be helpful in breaking down big, hard problems by idenitfying what the function should be and what parameters it might need. We then would have that function do what it needed to do such as for the triangle function we moved the pen forward and to the right to make a triangle. One example could be if we would like to draw a picture. We might want multiple different shapes in the picture so we could create a function for each shape to help make the picture. This is similar to this lab with the creation of triangles and rectangle.
2025-09-08 12:45:02 -04:00

25 lines
382 B
Python

# shapes.py
# ---------
# By MWC contributors
from turtle import *
def triangle(side_length):
forward(side_length)
right(120)
forward(side_length)
right(120)
forward(side_length)
right(120)
def rectangle(height, width):
forward(height)
right(90)
forward(width)
right(90)
forward(height)
right(90)
forward(width)
right(90)