Grandparents U, 2018 Part 2

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Grandparents U, 2018 Part 2"

Transcription

1 Grandparents U, 2018 Part 2 Computer Programming for Beginners Filip Jagodzinski

2 Preliminaries : Course Website All of these slides will be provided for you online... The URL for the slides are provided to you on your handout

3 Almost there Computer programming is done using a computer CODE, or coding You learn by making mistakes, sort of like learning how to ride the bicycle Q: How many people were involved in making Pokemon Go

4 Today A few of the more technical things that make life easier and coding less repetitive!

5 Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes

6 Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Create a screen & Background color

7 Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Create a new object of type turtle, and name it billy

8 Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Change the objects attributes

9 Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Modify the objects position

10 Turtle Graphics Finally some graphics Turtle # variable values color shape # functions Turtle() forward(int) left(int) This diagram represents the class Turtle It contains functions for modifying a Turtle object s attributes screen = turtle.screen() screen.bgcolor("lightgreen") # create turtle named billy billy = turtle.turtle() billy.color("red") billy.shape("turtle") billy.speed(10) billy.forward(60) billy.up() billy.goto(50,120) billy.down() billy.color("purple") billy.stamp() # create a turtle named susan susan = turtle.turtle() susan.color( blue ) susan.left(165) susan.forward(50) Create a second object of type turtle, and name it susan

11 Functions And if you need to do the same thing OVER and OVER again In addition to using Python s functions (such as print), you can create your OWN function, and then use it over and over again as needed. Here s how

12 Functions And if you need to do the same thing OVER and OVER again First, define a function The format is def functionname(): And in the body of the function include your code

13 Functions And if you need to do the same thing OVER and OVER again Then, you can invoke the function Multiple times to run it Q: What do you think this draws?

14 Functions And if you need to do the same thing OVER and OVER again Then, you can invoke the function Multiple times to run it

15 Today Continue to work on in-lab exercises proceed to graphics when you are ready