generated from mwc/lab_names
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:
parent
4cdc727194
commit
77075236c7
16
shapes.py
16
shapes.py
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue