Introduction To Math With Python Turtle
Introduction To Math With Python Turtle
Angle
Circle
Variable
PYTHON
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)
EXERCISE 2: USING 650 ANGLE
import turtle
t=
turtle.Turtle()
t.forward(50)
t.left(60)
t.forward(50)
t.left(60)
t.forward(50)
t.left(60)
t.forward(50)
t.left(60)
t.forward(50)
t.left(60)
t.forward(50)
t.left(60)
EXERCISE3: USING 450 ANGLE
import turtle
t=
turtle.Turtle()
t.forward(50)
t.left(45)
t.forward(50)
t.left(45)
t.forward(50)
t.left(45)
t.forward(50)
t.left(45)
t.forward(50)
t.left(45)
t.forward(50)
t.left(45)
t.forward(50)
t.left(45)
t.forward(50)
t.left(45)
CIRCLE
PYTHON FUNCTION: CIRCLE()
import turtle
t=
turtle.Turtle()
t.circle(5)
t.circle(10)
t.circle(15)
t.circle(20)
t.circle(40)
t.circle(60)
VARIABLE
VARIABLE
import turtle
t=
r=5 # radius =
turtle.Turtle()
t.circle(r) 5
t.circle(r*2)
t.circle(r*3)
r = 20 # radius =
t.circle(r) 20
t.circle(r*2)
t.circle(r*3)
SHAPE(), PENUP(), PENDOWN()
PYTHON FUNCTION SHAPE(), PENUP(),
PENDOWN()
Shape(shapename) – Shapename can be ‘arrow’,
‘classic’, ‘turtle’ or ‘circle’
Penup() and Pendown() commands are used to move
around the screen
Pencolor(color) – Sets the color of the pen.
Pensize(size) – Sets the thickness of the pen.
EXERCISE 6: PENUP() & PENDOWN()
import turtle
t =
turtle.Turtle()
t.shape("turtle")
t.stamp()
t.penup()
t.forward(30)
t.pendown()
t.stamp()
t.penup()
t.forward(30)
t.pendown()
t.stamp()
PROJECT
OLYMPICS
import turtle
t=
turtle.Turtle("turtle")
t.pensize(10)
t.penup()
t.setposition(-120, 60)
t.pendown()
t.color("blue")
t.circle(50)
t.penup()
t.setposition(-60, 0)
t.pendown()
t.color("yellow")
t.penup()
t.setposition(0, 60)
t.pendown()
t.color("black")
t.circle(50)
t.penup()
t.setposition(60, 0)
t.pendown()
t.color("green")
t.circle(50)
t.penup()
t.setposition(120,60)
t.pendown()
t.color("red")
t.circle(50)
CONDITIONAL STATEMENT
CONDITIONAL STATEMENT
Conditional statements are used to check conditions and change the behavior
of the program accordingly.
Syntax:
if EXPRESSION:
STATEMENTS
The colon (:) is significant and required. It separates the header of the
compound statement from the body.
The line after the colon must be indented (use four spaces for indenting).
All lines indented the same amount after the colon will be executed whenever
the EXPRESSION is true.
CONDITIONAL OPERATOR
import turtle
t = turtle.Turtle()
t.shape("turtle")
points = input(“Enter Points between 0 and 100: ")
Points = int (points)
if Points >= 90 and Points < 100:
t.left(90)
elif Points >= 80 and Points < 90: t.right(90)
else:
t.left(0) t.forward(100)
NR Computer Learning Center
1835 W. Orangewood, Suite
200
Orange, CA 92868
(714) 505-3475
www.nrclc.com