I have reached checkpoint 2.

A function and variable are alike since a variable gives a name to a certain value while a function gives a name to a larger amount of values.
They both shorten and simplify what needs to be typed in the program as well.
Functions might be useful in breaking down big, hard problems because you can work on a certain aspect of the problem and then create a function so you don't have to worry about that small piece of the problem again.
For example when working on the turtle lab, since I used a lot of repeated symmetry, this would have been simpler if I could define some functions.
This commit is contained in:
Lauren Dawnkaski 2024-09-06 07:57:04 -04:00
parent 4cdc727194
commit 77075236c7
1 changed files with 14 additions and 2 deletions

View File

@ -5,7 +5,19 @@
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)