




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
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