Function
Function
A grouping of programming instructions under a single name
Functions
Programmers can use functions created by their partners, relying on the functionality without needing to know the specific details of how the function is implemented.
Functions
Should be clearly named to help other people better understand programs
Functions
Can standalone, or take parameters
t.right(180)
t.xcor()
Abstraction
Abstraction
A simplified representation of something more complex.
Abstractions
Allow you to hide details to help you manage complexity, focus on relevant concepts, and reason about problems at a higher level.
ctrl + /
Do Now
- Go to repl.it ➝ my repls
- Create new Python Turtle repl (click red + at bottom right)
- Copy & paste your code from Keyboard Control 1
import turtle
player1 = turtle.Turtle()
world = turtle.Screen()
world.bgcolor("black")
world.listen()
player1.penup()
player1.color("red")
player1.shape("turtle")
def moveUp():
player1.sety(player1.ycor() +20)
def moveDown():
player1.sety(player1.ycor() -20)
def moveLeft():
player1.setx(player1.xcor() -20)
def moveRight():
player1.setx(player1.xcor() +20)
world.onkey(moveUp, "Up")
world.onkey(moveDown, "Down")
world.onkey(moveLeft, "Left")
world.onkey(moveRight, "Right")
you'll need this for classwork today, so copy this if you don't have it
functions
By Michelle Lim
functions
- 794