






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
Key points in this Introduction to Computing Using Python lecture are: Function Calls, How Do Functions Work, Function Call, Execute Function Body, Create a Frame, How to Draw Things, Online Python Tutor . Objectives of this course are: 1.Fluency in (Python) procedural programming 2. Competency in object-oriented programming 3. Knowledge of searching and sorting algorithms
Typology: Slides
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Announcements
The kid spoke. Very squeakily. "I charge you ... to ... to..." Get on with it! "T-t-tell me your n-name." That's usually how they start, the young ones. Meaningless waffle. He knew, and I knew that he knew, my name already; otherwise how could he have summoned me in the first place? You need the right words, the right actions, and most of all the right name. I mean, it's not like hailing a cab − you don't get just anybody, when you call. ... "I am Bartimaeus! I am Sakhr al-Jinni, N'gorso the Mighty, and the Serpent of Silver Plumes! I have rebuilt the walls of Uruk, Karnak, and Prague. I have spoken with Solomon....I am Bartimaeus! I recognize no master!" − The Amulet of Samarkand, Jonathan Stroud
Q: Why is it important to understand the notation for and mechanics of variables, objects, and frames? A: You get a clear model of what names are accessible and what objects they refer to. Bonus: you'll understand error messages better.
So, to review: what is a variable (in Python)? A name for referring to a value/ object. Two names can refer to the same thing; example: "that person talking in front of the room" and "the CS1110 prof with black hair".
What a name refers to can change (hence the name "variable"): "that person talking in front of the room" could refer to the person Prof. Lee at one time, and the person Prof. Marschner at another).
What is an object? An actual thing that can be referred to.
What is an ID? The unique identifier --- "one true name" --- for an object. Each object has a distinct id.
What is a frame? The function's "local view of the world": the names it defines and uses locally. These names disappear when the function call finishes.
import lec lt_speed = 3e lec07.violate_physics(...)
code with function call
function "definition" (in lec07.py)
violate_physics:...
def violate_physics(...?): """Changes lt_speed""" (^1) ...?
lt_speed 3 × 108
*Given the Python we know at this point, where all assignments to a "plain variable" (not expressions with a "dot" in them) within a function are treated as referring to a local variable.
That is, if lt_speed is a variable, can you write a function violate_physics(...) that changes the value of lt_speed?
What does your code for violate_physics look like? (A) 0 params, 0 local vars (B) 1 param, 0 local vars (C) 0 params, 1 local var (D) ≥1 of each (E) There can't be such a function
import lec lt_speed = 3e lec07.v_p_try1()
code with function call
function definition
v_p_try1: 1
def v_p_try1(): """Changes lt_speed""" (^1) lt_speed = 42.
lt_speed 3 × 108
That is, if lt_speed is a variable, can you write a function violate_physics(...) that changes the value of lt_speed?
lt_speed 42.
*Given the Python we know at this point, where all assignments to a "plain variable" (not expressions with a "dot" in them) within a function are treated as referring to a local variable.
import lec lt_speed = 3e lec07.v_p_try3(lt_speed)
code with function call
function definition
v_p_try3: 1
def v_p_try3(lt_speed): """Changes lt_speed to 42.0""" (^1) lt_speed = 42.
lt_speed 3 × 108
That is, if lt_speed is a variable, can you write a function violate_physics(...) that changes the value of lt_speed?
lt_speed 3 × 108
✗
note: only one lt_speed in the frame
*Given the Python we know at this point, where all assignments to a "plain variable" (not expressions with a "dot" in them) within a function are treated as referring to a local variable.
import lec lt_speed = 3e lt_speed = lec07.boring(-3e8)
code with function call
function definition
def boring(new): """Returns new""" (^1) return new
lt_speed 3 × 108 -3 × 108
That is, if lt_speed is a variable, can you write a function violate_physics(...) that changes the value of lt_speed?
✗
How many things are wrong with this picture?
(A) 0-1 (B) 1-2 (C) 3-5 (D) more than 5 (E) You mean besides the fact that you think I can answer this? [note: the ...distanceFrom... value will be 5.0]
pt norm
pt.x pt.y pt.z
rescale: 5
p 5
p id Point x 0. y 3. z 4.
id Point x 0. y 0. z 0.
p_new