




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A set of lecture notes for a computer science course, cpsc 121, taught in fall 2011. The notes cover the topics of variables and basic turtle graphics. Explanations of variables, their naming rules, and reference diagrams. It also includes exercises for the reader to practice. Additionally, it introduces the turtle module and explains how to use it for drawing.
Typology: Study notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Today ...
Homework
Reading Assignment
A variable is a name (label) that “refers” to (i.e., “references”) a value
Assignment statements create new variables and give them values
course = "CPSC121" year = 2011 pi = 3.
Each variable refers to its assigned value
course ’CPSC121’
We’ll often denote the value of a variable using an arrow
course −→ "CPSC121"
We can use variables in place of their values
type(pi) <class ’float’>
Variables can be reassigned (example of “dynamic typing”)
pi = course # note: assigned a string! type(pi) <class ’str’>
Statments within a sequence of statements are evaluated in order ...
Assignment statements can make this a bit tricky
For example:
x = 100 y = 200 z = x x = 300 After these statements are executed, was is the value of x?
Reference (aka state and memory) diagrams can help!
x, z −→ 100 y −→ 200
z −→ 100 y −→ 200 x −→ 300
Excercise: After these statements are executed ...
x = 15 y = x x = 20 z = y y = x + z z = 5
What are the values of x, y, and z?
Some general hints about assignment
import turtle pen = turtle.Turtle() pen.goto(0, 100) pen.goto(100, 100) pen.goto(100, 0) pen.goto(0, 0)
pen.undo()
A statement is a chunk of code the interpreter can execute
So far we’ve looked at 3 simple kinds
After entering a statement into the intepreter