week 7 functions with turtle graphics Flashcards
turtle graphics
python module for learning drawing
importing turtle module syntax
import turtle
import random
setting up turtle screen
s = turtle.getscreen()
setting up turtle object
t = turtle.Turtle()
change color of screen
originally black, but can be changed with the following function
s.bgcolor(‘blue’)
turtle screen
center is (0,0), like a graph (100 is typically a quarter of the way through)
customize turtle
you can customize speed, shape, fill color, pen color, and width
customize turtle syntax
t.width(5)
function
‘blueprint’ you can call onto later to repeat a chunk of code many times
function syntax
def funName():
# function body
function call syntax
funName()
how do you call a function repeatedly?
with a for loop
purpose of a function
improve code readability, reduce redundancy, facilitate modular/incremental programming
function parameters
assigns variables that are defined when function is called
basically input arguments and what they are called in terms of the function
random.randint()
randomly generates integers between and including two arguments