Programming is my favorite thing
Who has programmed before?
Computers do exactly what you tell them to do if you can program you can do almost anything
Syntax matters - computers are very particular about how they understand things
Who has brushed their teeth before?
Sequence of steps
Are my teeth clean or has 2 minutes passed If I have two toothpastes pick my favorite.
we decide when to do things
Do it two times a day Move it back and forth a number of times
Using other people’s programs https://docs.python.org/2/library/turtle.html
Instantiating turtle
t = turtle.Turtle()
t is a variable and we assign a value to it
right(degrees)
left(degrees)
forward(distance)
backward(distance)
home()
circle(radius)
t.color(‘blue’)
Turtle starts facing east You’re the turtle
import turtle
t = turtle.Turtle()
t.forward(100)
t.left(90)
t.color("blue")
t.forward(100)
t.left(90)
import turtle
t = turtle.Turtle()
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
repeating count from zero
print("start test")
for i in range(4):
print(i)
print("test")
print("end test 1")
for banana in range(20):
print(banana)
print(banana * 2)
import turtle
t = turtle.Turtle()
for i in range(4):
t.forward(100)
t.left(90)
import turtle
t = turtle.Turtle()
for i in range(3):
t.forward(100)
t.left(120)
import turtle
t = turtle.Turtle()
for i in range(4):
t.forward(75)
t.left(90)
import turtle
t = turtle.Turtle()
for i in range(6):
t.forward(75)
t.left(60)
import turtle
t = turtle.Turtle()
for i in range(8):
t.forward(75)
t.left(45)
import turtle
star = turtle.Turtle()
for i in range(50):
star.forward(50)
star.right(144)
#END_SRC
What's the minimum number of loops?
import turtle
spiral = turtle.Turtle()
for i in range(20):
spiral.forward(i * 10)
spiral.right(144)
import turtle
painter = turtle.Turtle()
painter.color("blue")
for i in range(50):
painter.forward(50)
painter.left(123) # Let's go counterclockwise this time
painter.color("red")
for i in range(50):
painter.forward(100)
painter.left(123)
Take X for sides and draw any shape! (1-1000)
- use variables to store our values
- 180(n-2)/n gives you the interior angle of a regular polygon - where n is the number of sides