Lecture 9: Memory in Python

Size: px
Start display at page:

Download "Lecture 9: Memory in Python"

Transcription

1 Lecture 9: Memory in Python CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

2 Feb 27: CS 1110: Announcements Last call for a one-on-one! CMS: OPTIONAL: one-on-ones Prelim 1 is March 13. You have until March 1st, 11:59pm to register a conflict or a need for accommodation. There is no single makeup session. See website: Assessment à Exams CMS: Prelim 1 conflicts A1 Revisions: open from Mar 1 st thru Mar 7, 11:59pm.

3 Storage in Python Round 1 Global Space What you start with Stores global variables Lasts until you quit Python Global Space p id2

4 Folders Live on the Heap p = shapes.point3(1,2,3) p lives in the Global Space. Its folder lives on the Heap. Global Space p id5 Heap Space id5 Point3 x 1 y 2 z 3

5 Storage in Python Round 2 Global Space What you start with Stores global variables Lasts until you quit Python Heap Space Where folders are stored Have to access indirectly Global Space p id2 Heap Space id2

6 Calling a Function Creates a Call Frame p = shapes.point3(1,2,3) incr_x(p) Global Space Heap Space p id5 id5 Point3 Call Frame x 1 y 2 z 3 incr_x 1 the_point id5

7 What goes in a Call Frame? p = shapes.point3(1,2,3) def incr_x(the_point): the_point.x = the_point.x+1 incr_x(p) (1) Boxes for parameters at the start of the function (2) Boxes for variables local to the function as they are created Global Space p id5 Call Frame incr_x 1 the_point id5

8 Storage in Python Round 3 Global Space What you start with Stores global variables Lasts until you quit Python Heap Space Where folders are stored Have to access indirectly Call Frames Parameters Other variables local to function Lasts until function returns Global Space Call Frames p f1 f2 id2 Heap Space id2

9 Frames and Helper Functions Functions can call each other! Each call creates a new call frame Writing the same several lines of code in 2 places? Or code that accomplishes some conceptual sub-task? Write a helper function! Makes your code easier to: Read Write Edit Debug 9

10 From before: last_name_first def last_name_first(n): """Returns: copy of <n> but in the form <last-name>, <first-name> Precondition: <n> is in the form <first-name> <last-name> with one or more blanks between the two names. """ space_index = n.find(' ') first = n[:space_index] last = n[space_index+1:].strip() return last+', '+first last_name_first('haruki Murakami') gives 'Murakami, Haruki' last_name_first('haruki Murakami') gives ' Murakami, Haruki' 10

11 Frames and Helper Functions def first_name(s): """Prec: see last_name_first""" 4 end = s.find(' ') 5 return s[0:end] def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + ',' + first def last_name(s): """Prec: see last_name_first""" 6 7 end = s.rfind(' ') return s[end+1:] rfind gets the last instance of substring 11

12 Drawing Frames for Helper Functions (1) def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + ',' + first last_name_first 1 s 'Haruki Murakami' def first_name(s): """Prec: see last_name_first""" 4 end = s.find(' ') 5 return s[0:end] last_name_first('haruki Murakami') 12

13 Drawing Frames for Helper Functions (2) def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + ',' + first def first_name(s): """Prec: see last_name_first""" end = s.find(' ') return s[0:end] Not done. Do not erase! last_name_first 1 s 'Haruki Murakami' first_name 4 s 'Haruki Murakami' last_name_first('haruki Murakami') 13

14 Drawing Frames for Helper Functions (3) def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + ',' + first def first_name(s): """Prec: see last_name_first""" end = s.find(' ') return s[0:end] last_name_first 1 s 'Haruki Murakami' first_name 5 s 'Haruki Murakami' end 6 last_name_first('haruki Murakami') 14

15 Drawing Frames for Helper Functions (4) def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + ',' + first def first_name(s): """Prec: see last_name_first""" end = s.find(' ') return s[0:end] last_name_first 1 s 'Haruki Murakami' first_name s 'Haruki Murakami' end 6 RETURN 'Haruki' last_name_first('haruki Murakami') 15

16 Question: What Happens Next? def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + ',' + first def first_name(s): """Prec: see last_name_first""" end = s.find(' ') return s[0:end] C: last_name_first('haruki Murakami') last_name_first 1 s first_name s 'Haruki Murakami' 'Haruki Murakami' end 6 RETURN 'Haruki' ERASE FRAME #1 ERASE FRAME #2 A: last_name_first 2 B: Stuff ERASE FRAME #2 last_name_first 2 Stuff first_name Stuff

17 Answer: What Happens Next? def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + ',' + first def first_name(s): """Prec: see last_name_first""" end = s.find(' ') return s[0:end] C: last_name_first('haruki Murakami') last_name_first 1 s first_name s 'Haruki Murakami' 'Haruki Murakami' end 6 RETURN 'Haruki' ERASE FRAME #1 ERASE FRAME #2 A: last_name_first 2 B: Stuff ERASE FRAME #2 last_name_first 2 Stuff first_name Stuff

18 Drawing Frames for Helper Functions (5) def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + '.' + first last_name_first 2 s first 'Haruki Murakami' 'Haruki' def last_name(s): """Prec: see last_name_first""" 6 end = s.rfind(' ') 7 return s[end+1:] last_name_first('haruki Murakami')

19 Drawing Frames for Helper Functions (6) def last_name_first(s): """Precondition: s in the form <first-name> <last-name>""" first = first_name(s) last = last_name(s) return last + '.' + first def last_name(s): """Prec: see last_name_first""" end = s.rfind(' ') return s[end+1:] last_name_first 2 s 'Haruki Murakami' first 'Haruki' last_name 6 s 'Haruki Murakami' last_name_first('haruki Murakami') 19

20 The Call Stack Functions frames are stacked Cannot remove one above w/o removing one below Python must keep the entire stack in memory Error if it cannot hold stack ( stack overflow ) function1 function2 function3 function4 function5 calls calls calls calls 20

21 Call Stack Example (1) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 14

22 Call Stack Example (2) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 14 basic_line 11

23 Call Stack Example (3) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 14 basic_line 11 happy_birthday 2

24 def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Stack Example (4) Call Frame Stack song basic_line happy_birthday RETURN None Happy Birthday

25 Call Stack Example (5) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 14 basic_line 12 Happy Birthday

26 Call Stack Example (6) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 14 basic_line 12 to_you 6 Happy Birthday

27 Call Stack Example (7) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 14 basic_line 12 to_you RETURN None Happy Birthday to you

28 Call Stack Example (8) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 14 basic_line RETURN None Happy Birthday to you

29 Call Stack Example (9) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 15 Happy Birthday to you

30 Call Stack Example (9) def : print( Happy Birthday ) def dear(): print( Dear James ) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Call Frame Stack song 15 basic_line 11 Happy Birthday to you

31 Errors and the Call Stack def : print( Happy Birthday ) def dear(): print( Dear +name) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Happy Birthday to you Happy Birthday to you Happy Birthday Traceback (most recent call last): File "birthday_error.py", line 18, in <module> song() File "birthday_error.py", line 16, in song line_with_name() File "birthday_error.py", line 9, in line_with_name dear() File "birthday_error.py", line 4, in dear print("dear "+name) NameError: name 'name' is not defined Make sure you can see line numbers in Komodo. 31 Preferences è Editor

32 Errors and the Call Stack, in Color! def : print( Happy Birthday ) def dear(): print( Dear +name) def to_you(): print( to you ) def line_with_name(): dear() def : to_you() def song(): line_with_name() song() Script code. Global space Happy Birthday to you Happy Birthday to you Happy Birthday Traceback (most recent call last): File "birthday_error.py", line 18, in <module> song() File "birthday_error.py", line 16, in song line_with_name() File "birthday_error.py", line 9, in line_with_name dear() File "birthday_error.py", line 4, in dear print("dear "+name) NameError: name 'name' is not defined Where error was found 32

33 Functions and Global Space A function definition Creates a global variable (same name as function) Creates a folder for body Puts folder id in variable INCHES_PER_FT = 12 def get_feet(ht_in_inches): return ht_in_inches // INCHES_PER_FT Body Global Space Heap Space INCHES_PER_FT 12 get_feet id6 See for yourself: id6 Body function 33

34 Function Definition vs. Call Frame Global Space Heap Space (Function definition goes here) Call Frame (memory for function call goes here) It s alive! 34

35 Modules and Global Space import Creates a global variable (same name as module) Puts variables, functions in a folder Puts folder id in variable import math Global Space math id5 Heap Space id5 module pi e functions 35

36 Modules, Objects, Call Frames (1) import shapes def incr_x(pt): pt.x = pt.x+1 Global Space Heap Space p = shapes.point3(1,2,3) incr_x(p) Narration: Python knows there is a shapes module And it knows where to find it (à on the Heap).

37 Modules, Objects, Call Frames (2) import shapes def incr_x(pt): pt.x = pt.x+1 Global Space Heap Space p = shapes.point3(1,2,3) incr_x(p) Narration: Python knows there is a function called incr_x And it knows where to find the definition (à on the Heap).

38 Modules, Objects, Call Frames (3) import shapes def incr_x(pt): pt.x = pt.x+1 Global Space Heap Space p = shapes.point3(1,2,3) incr_x(p) Narration: Python just created a point p. p lives in the Global Space. Its folder lives on the Heap.

39 Modules, Objects, Call Frames (4) import shapes def incr_x(pt): pt.x = pt.x+1 Global Space Heap Space p = shapes.point3(1,2,3) incr_x(p) Call Frame Narration: Python just created a call frame for the function incr_x Parameter pt lives in the call frame. Its value is whatever the argument to incr_x was.

40 Modules, Objects, Call Frames (5) import shapes def incr_x(pt): pt.x = pt.x+1 Global Space Heap Space p = shapes.point3(1,2,3) incr_x(p) Call Frame Narration: Python is about to execute the first instruction in the function incr_x

41 Modules, Objects, Call Frames (6) import shapes def incr_x(pt): pt.x = pt.x+1 Global Space Heap Space p = shapes.point3(1,2,3) incr_x(p) Call Frame Narration: Python just executed the lone instruction in the function incr_x. Since there is no return statement, the return value of NONE is created in the call frame.

42 Modules, Objects, Call Frames (7) import shapes def incr_x(pt): pt.x = pt.x+1 Global Space Heap Space p = shapes.point3(1,2,3) incr_x(p) Narration: Python just returned from the function incr_x. Its call frame is destroyed because the function is done.

43 Storage in Python (Final Version!) Global Space What you start with Stores global variables, modules & functions Lasts until you quit Python Heap Space Where folders are stored Have to access indirectly Call Frame Stack Parameters Other variables local to function Lasts until function returns Global Space Call Frame Stack p f1 f2 id2 Heap Space id2

44 Global & Local Variables print("welcome to the Star Wars Name Generator!") print("inputs must be 3 letters or longer. What is your...") first = input("...first name? ") middle = input("...middle name? ") last = input("...last name? ") town = input("...hometown? ") def make_name(name1, name2): name = name1[0:3]+name2[0:3].lower() return name new_first = make_name(first, last) new_last = make_name(middle, town) print("your Star Wars name is: "+new_first+" "+new_last) 45

45 Global & Local Variables print("welcome to the Star Wars Name Generator!") print("inputs must be 3 letters or longer. What is your...") first = input("...first name? ") middle = input("...middle name? ") last = input("...last name? ") town = input("...hometown? ") def make_name(name1, name2): name = name1[0:3]+name2[0:3].lower() return name Question: What if these parameters were called first & last? new_first = make_name(first, last) new_last = make_name(middle, town) print("your Star Wars name is: "+new_first+" "+new_last) 46

46 Global & Local Variables print("welcome to the Star Wars Name Generator!") print("inputs must be 3 letters or longer. What is your...") first = input("...first name? ") middle = input("...middle name? ") last = input("...last name? ") town = input("...hometown? ") def make_name(name1, name2): name = name1[0:3]+name2[0:3].lower() return name Question: What if this variable were called first? new_first = make_name(first, last) new_last = make_name(middle, town) print("your Star Wars name is: "+new_first+" "+new_last) 47

Lecture 10. Memory in Python

Lecture 10. Memory in Python Lecture 0 Memory in Python Announcements For This Lecture Reading Reread all of Chapter 3 Assignments Work on your revisions Want done by Sunday Survey: 50 responded Remaining do by tomorrow Avg Time:

More information

Lecture 9. Memory and Call Stacks

Lecture 9. Memory and Call Stacks Lecture 9 Memory and Call Stacks Announcements for Today Assignment 1 Reading We have started grading! Should have your grade tomorrow morning Resubmit until correct If you were close Will get feedback

More information

Lecture 4: Defining Functions (Ch ) CS 1110 Introduction to Computing Using Python

Lecture 4: Defining Functions (Ch ) CS 1110 Introduction to Computing Using Python http://www.cs.cornell.edu/courses/cs0/209sp Lecture 4: Defining Functions (Ch..4-.) CS 0 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

Lecture 8: Conditionals & Control Flow (Sections ) CS 1110 Introduction to Computing Using Python

Lecture 8: Conditionals & Control Flow (Sections ) CS 1110 Introduction to Computing Using Python http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 8: Conditionals & Control Flow (Sections 5.1-5.7) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

Lecture 6: Specifications & Testing

Lecture 6: Specifications & Testing http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 6: Specifications & Testing (Sections 4.9, 9.5) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

Lecture 10: Lists and Sequences

Lecture 10: Lists and Sequences http://www.cs.cornell.edu/courses/cs/8sp Lecture : Lists and Sequences (Sections.-.,.4-.6,.8-.) CS Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van

More information

Last Name: First Name: Cornell NetID, all caps: CS 1110 Regular Prelim 1 Solutions March 2018

Last Name: First Name: Cornell NetID, all caps: CS 1110 Regular Prelim 1 Solutions March 2018 Last Name: First Name: Cornell NetID, all caps: CS 1110 Regular Prelim 1 Solutions March 2018 1. [7 points] What s the point? Consider the Point3 class as it was defined in lecture, with 3 attributes:

More information

CS 1110 Prelim 1, March 2018

CS 1110 Prelim 1, March 2018 Last Name: First Name: Cornell NetID, all caps: CS 1110 Prelim 1, March 2018 This 90-minute exam has 7 questions worth a total of 69 points. You may separate the pages while working on the exam; we have

More information

CS Prelim 1 Review Fall 2018

CS Prelim 1 Review Fall 2018 CS 1110 Prelim 1 Review Fall 2018 Exam Info Prelim 1: Thursday, October 12th Last name A D at 5:15 6:45 in Uris G01 Last name E K at 5:15 6:45 in Statler Aud. Last name L P at 7:30 9:00 in Uris G01 Last

More information

Lecture 26: Sorting CS 1110 Introduction to Computing Using Python

Lecture 26: Sorting CS 1110 Introduction to Computing Using Python http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 26: Sorting CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White] Academic

More information

CS Prelim 1 Review Fall 2013

CS Prelim 1 Review Fall 2013 CS 1110 Prelim 1 Review Fall 2013 Exam Info Prelim 1: 7:30 9:00PM, Thursday, October 17th Last name A G in Olin 155 Last name H K in Olin 165 Last name L R in Olin 255 Last name S Z in Upson B17 To help

More information

CS Prelim 1 Review Fall 2017

CS Prelim 1 Review Fall 2017 CS 1110 Prelim 1 Review Fall 2017 Exam Info Prelim 1: 7:30 9:00PM, Thursday, October 12th Last name A J in Uris G01 Last name K Z in Statler Auditorium SDS Students will get an e-mail To help you study:

More information

Conditionals & Control Flow

Conditionals & Control Flow CS 1110: Introduction to Computing Using Python Lecture 8 Conditionals & Control Flow [Andersen, Gries, Lee, Marschner, Van Loan, White] Announcements: Assignment 1 Due tonight at 11:59pm. Suggested early

More information

Lecture 3: Functions & Modules

Lecture 3: Functions & Modules http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 3: Functions & Modules (Sections 3.1-3.3) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

Review 1. Call Frames; Diagramming Objects

Review 1. Call Frames; Diagramming Objects Review 1 Call Frames; Diagramming Objects The Big Issue Cannot answer questions on this topic unless you draw variables draw frames for function calls draw objects when they are created Learning to do

More information

Lecture 17: Classes (Chapter 15)

Lecture 17: Classes (Chapter 15) http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 17: Classes (Chapter 15) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

CS Prelim 1 Review Fall 2012

CS Prelim 1 Review Fall 2012 CS 1110 Prelim 1 Review Fall 2012 Exam Info Prelim 1: 7:30 9:00PM, Thursday, October 4th Last name A P in Kennedy 1116 Last name R T in Warren 131 Last name U Z in Warren 231 To help you study: Study guides,

More information

Lecture 3: Functions & Modules (Sections ) CS 1110 Introduction to Computing Using Python

Lecture 3: Functions & Modules (Sections ) CS 1110 Introduction to Computing Using Python http://www.cs.cornell.edu/courses/cs1110/2019sp Lecture 3: Functions & Modules (Sections 3.1-3.3) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

Lecture 4: Defining Functions

Lecture 4: Defining Functions http://www.cs.cornell.edu/courses/cs0/208sp Lecture 4: Defining Functions (Ch. 3.4-3.) CS 0 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W.

More information

CS 1110, LAB 3: STRINGS; TESTING

CS 1110, LAB 3: STRINGS; TESTING CS 1110, LAB 3: STRINGS; TESTING http://www.cs.cornell.edu/courses/cs1110/2017sp/labs/lab03.pdf First Name: Last Name: NetID: Getting Credit: Deadline: the first 10 minutes of (your) lab two weeks from

More information

CS Prelim 1 Review Fall 2016

CS Prelim 1 Review Fall 2016 CS 1110 Prelim 1 Review Fall 2016 Exam Info Prelim 1: 7:30 9:00PM, Thursday, October 13th Last name A J in Uris G01 Last name K Z in Statler Auditorium SDS Students will get an e-mail To help you study:

More information

Lecture 7. Memory in Python

Lecture 7. Memory in Python Lecture 7 Memory in Python Announcements For This Lecture Readings Reread Chapter 3 No reading for Thursday Lab Work on Assignment Credit when submit A Nothing else to do Assignment Moved to Fri, Sep.

More information

Lecture 11: Iteration and For-Loops

Lecture 11: Iteration and For-Loops http://www.cs.cornell.edu/courses/cs0/08sp Lecture : Iteration and For-Loops (Sections 4. and 0.3) CS 0 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C.

More information

CS Prelim 1 Review Fall 2013

CS Prelim 1 Review Fall 2013 CS 1110 Prelim 1 Review Fall 2013 Exam Info Prelim 1: 7:30 9:00PM, Thursday, October 17th Last name A G in Olin 155 Last name H K in Olin 165 Last name L R in Olin 255 Last name S Z in Upson B17 To help

More information

PREPARING FOR PRELIM 1

PREPARING FOR PRELIM 1 PREPARING FOR PRELIM 1 CS 1110: FALL 2012 This handout explains what you have to know for the first prelim. There will be a review session with detailed examples to help you study. To prepare for the prelim,

More information

Lecture 13. Call Stacks & Debugging

Lecture 13. Call Stacks & Debugging Lecture 13 Call Stacks & Debugging Announcements for This Lecture Prelim 1 TONIGHT 7:30-9pm Abel Price (Upson B17) Rabbit Teo (Upson 111) Ting Zytariuk (Upson 109) Graded late tonight Will have grade Fri

More information

CS1110. Lecture 6: Function calls

CS1110. Lecture 6: Function calls CS1110 Lecture 6: Function calls Announcements Grades for Lab 1 should all be posted in CMS. Please verify that you have a 1 if you checked off the lab. Let course staff know if your grade is missing!

More information

Lecture 17: Classes (Chapter 15)

Lecture 17: Classes (Chapter 15) http://www.cs.cornell.edu/courses/cs1110/018sp Lecture 17: Classes (Chapter 15) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

Lecture 24: Loop Invariants

Lecture 24: Loop Invariants http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 24: Loop Invariants [Online Reading] CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van

More information

Lecture 19: Subclasses & Inheritance (Chapter 18)

Lecture 19: Subclasses & Inheritance (Chapter 18) http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 19: Subclasses & Inheritance (Chapter 18) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

Lecture 5. Defining Functions

Lecture 5. Defining Functions Lecture 5 Defining Functions Announcements for this Lecture Last Call Quiz: About the Course Take it by tomorrow Also remember the survey Readings Sections 3.5 3.3 today Also 6.-6.4 See online readings

More information

CS 1110: Introduction to Computing Using Python Lists and Sequences

CS 1110: Introduction to Computing Using Python Lists and Sequences CS : Introduction to Computing Using Python Lecture Lists and Sequences [Andersen, Gries, Lee, Marschner, Van Loan, White] Prelim Lecture Announcements Date: Tuesday, March 4th, 7:3 pm to 9: pm Submit

More information

CS Lecture 25: Models, Views, Controllers, and Games. Announcements

CS Lecture 25: Models, Views, Controllers, and Games. Announcements CS 1110 Lecture 25: Models, Views, Controllers, and Games Announcements A5 is out! Get started right away you need time to ask questions. Office/consulting hours will be changing for study week. See the

More information

Lecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python

Lecture 7: Objects (Chapter 15) CS 1110 Introduction to Computing Using Python htt://www.cs.cornell.edu/courses/cs1110/2018s Lecture 7: Objects (Chater 15) CS 1110 Introduction to Comuting Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]

More information

Lecture 5: Strings

Lecture 5: Strings http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 5: Strings (Sections 8.1, 8.2, 8.4, 8.5, 1 st paragraph of 8.9) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries,

More information

CS Lecture 26: Subclasses in Event-driven Programs A7 is out! Get started right away you need time to ask questions.

CS Lecture 26: Subclasses in Event-driven Programs A7 is out! Get started right away you need time to ask questions. CS 1110 Lecture 26: Subclasses in Event-driven Programs A7 is out! Get started right away you need time to ask questions. Academic integrity Please be careful: do not share your code or look at other groups

More information

Lecture 20: While Loops (Sections 7.3, 7.4)

Lecture 20: While Loops (Sections 7.3, 7.4) http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 20: While Loops (Sections 7.3, 7.4) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van

More information

Iteration and For Loops

Iteration and For Loops CS 1110: Introduction to Computing Using Python Lecture 11 Iteration and For Loops [Andersen, Gries, Lee, Marschner, Van Loan, White] Rooms: Announcements: Prelim 1 aa200 jjm200 Baker Laboratory 200 jjm201

More information

CS 1110 Prelim 1 October 17th, 2013

CS 1110 Prelim 1 October 17th, 2013 CS 1110 Prelim 1 October 17th, 2013 This 90-minute exam has 6 questions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need

More information

CS1110. Lecture 6: Function calls

CS1110. Lecture 6: Function calls CS1110 Lecture 6: Function calls Announcements Additional space in labs: We have added some space and staffing to the 12:20 and 1:25 labs on Tuesday. There is still space to move into these labs. Printed

More information

CS 1110: Introduction to Computing Using Python Loop Invariants

CS 1110: Introduction to Computing Using Python Loop Invariants CS 1110: Introduction to Computing Using Python Lecture 21 Loop Invariants [Andersen, Gries, Lee, Marschner, Van Loan, White] Announcements Prelim 2 conflicts due by midnight tonight Lab 11 is out Due

More information

CS 1110 SPRING 2016: LAB 3: PRACTICE FOR A2 (Feb 23-24)

CS 1110 SPRING 2016: LAB 3: PRACTICE FOR A2 (Feb 23-24) CS 1110 SPRING 2016: LAB 3: PRACTICE FOR A2 (Feb 23-24) http://www.cs.cornell.edu/courses/cs1110/2016sp/labs/lab03/lab03.pdf First Name: Last Name: NetID: The lab assignments are very important. Remember

More information

CS 1110 Prelim 1 October 4th, 2012

CS 1110 Prelim 1 October 4th, 2012 CS 1110 Prelim 1 October 4th, 01 This 90-minute exam has 6 questions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need more

More information

CS 1110 Prelim 1 October 15th, 2015

CS 1110 Prelim 1 October 15th, 2015 CS 1110 Prelim 1 October 15th, 2015 This 90-minute exam has 6 uestions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need more

More information

Lecture 3. Functions & Modules

Lecture 3. Functions & Modules Lecture 3 Functions & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students should

More information

CS Lecture 19: Loop invariants

CS Lecture 19: Loop invariants CS 1110 Lecture 19: Loop invariants Announcements Prelim 2 conflicts Today (April 2) is two weeks before the prelim, and the deadline for submitting prelim conflicts. Instructor travel This week and the

More information

Lecture 3. Functions & Modules

Lecture 3. Functions & Modules Lecture 3 Functions & Modules Labs this Week Lab 1 is due at the beginning of your lab If it is not yet by then, you cannot get credit Only exception is for students who added late (Those students should

More information

Lecture 11. Asserts and Error Handling

Lecture 11. Asserts and Error Handling Lecture 11 Asserts and Error Handling Announcements for Today Reading Reread Chapter 3 10.0-10.2, 10.4-10.6 for Thu Prelim, Oct 13 th 7:30-9:00 Material up October 4th Study guide next week Conflict with

More information

Lecture 4. Defining Functions

Lecture 4. Defining Functions Lecture 4 Defining Functions Academic Integrity Quiz Reading quiz about the course AI policy Go to http://www.cs.cornell.edu/courses/cs11110/ Click Academic Integrity in side bar Read and take quiz in

More information

Lecture 4. Defining Functions

Lecture 4. Defining Functions Lecture 4 Defining Functions Academic Integrity Quiz Remember: quiz about the course AI policy Have posted grades for completed quizes Right now, missing ~130 enrolled students If did not receive at least

More information

Lecture 2: Variables & Assignments

Lecture 2: Variables & Assignments http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 2: Variables & Assignments (Sections 2.1-2.3,2.5) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

CS 1110 Prelim 1 March 15th, 2016

CS 1110 Prelim 1 March 15th, 2016 Circle your lab/situation: CS 1110 Prelim 1 March 15th, 2016 ACCEL: Tue 12:20 Tue 1:25 Tue 2:30 Tue 3:35 ACCEL : Wed 10:10 Wed 11:15 Wed 12:20 Wed 1:25 Wed 2:30 Wed 3:35 PHILLIPS : Tue 12:20 Tue 1:25 Wed

More information

PREPARING FOR THE FINAL EXAM

PREPARING FOR THE FINAL EXAM PREPARING FOR THE FINAL EXAM CS 1110: FALL 2017 This handout explains what you have to know for the final exam. Most of the exam will include topics from the previous two prelims. We have uploaded the

More information

Lecture 4. Defining Functions

Lecture 4. Defining Functions Lecture 4 Defining Functions Academic Integrity Quiz Remember: quiz about the course AI policy Have posted grades for completed quizes Right now, missing ~90 enrolled students If did not receive perfect,

More information

CS 1110, LAB 03: STRINGS; TESTING First Name: Last Name: NetID:

CS 1110, LAB 03: STRINGS; TESTING  First Name: Last Name: NetID: CS 1110, LAB 03: STRINGS; TESTING http://www.cs.cornell.edu/courses/cs1110/2018sp/labs/lab03/lab03.pdf First Name: Last Name: NetID: Correction on pg 2 made Tue Feb 13, 3:15pm Getting Credit: As always,

More information

Lecture 11. Asserts and Error Handling

Lecture 11. Asserts and Error Handling Lecture 11 Asserts and Error Handling Announcements for Today Reading Reread Chapter 3 10.0-10.2, 10.4-10.6 for Thu Prelim, Oct 12 th 7:30-9:00 Material up October 3rd Study guide next week Conflict with

More information

Lecture 18: Using Classes Effectively (Chapter 16)

Lecture 18: Using Classes Effectively (Chapter 16) http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 18: Using Classes Effectively (Chapter 16) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner,

More information

CS1110. Lecture 22: Prelim 2 Review Session. Announcements. Processed prelim regrade requests: on the front table.

CS1110. Lecture 22: Prelim 2 Review Session. Announcements. Processed prelim regrade requests: on the front table. CS1110 Lecture 22: Prelim 2 Review Session Announcements Processed prelim regrade requests: on the front table. Reminders: Exam: 7:30 9:00PM, Tuesday Apr 16 th Kennedy 116 (Call Auditorium, same as before).

More information

Lecture 19. Operators and Abstraction

Lecture 19. Operators and Abstraction Lecture 19 Operators and Abstraction Announcements Reading Tuesday: Chapter 18 Thursday reading online Assignments A4 due tonight at Midnight 10 pts per day late Consultants available tonight A5 posted

More information

CS 1110 Prelim 2 November 14th, 2013

CS 1110 Prelim 2 November 14th, 2013 CS 1110 Prelim 2 November 14th, 2013 This 90-minute exam has 6 questions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need

More information

Review. Strings are stored character by character. Can access each character individually by using an index: "C" "o" "m" "p" "u" "t"

Review. Strings are stored character by character. Can access each character individually by using an index: C o m p u t Strings II Review Strings are stored character by character. Can access each character individually by using an index: 0 1 2 3 4 5 6 7 "C" "o" "m" "p" "u" "t" "e" "r" New NegaDve indexing can be used.

More information

CS Prelim 2 Review Fall 2018

CS Prelim 2 Review Fall 2018 CS 1110 Prelim 2 Review Fall 2018 Exam Info Prelim 1: Thursday, November 8th Last name L P at 5:15 6:45 in Uris G01 Last name Q Z at 5:15 6:45 in Statler Aud. Last name A D at 7:30 9:00 in Uris G01 Last

More information

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS   First Name: Last Name: NetID: CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS http://www.cs.cornell.edu/courses/cs1110/2018sp/labs/lab01/lab01.pdf First Name: Last Name: NetID: Learning goals: (1) get hands-on experience using Python in

More information

CS 1110, LAB 10: ASSERTIONS AND WHILE-LOOPS 1. Preliminaries

CS 1110, LAB 10: ASSERTIONS AND WHILE-LOOPS  1. Preliminaries CS 0, LAB 0: ASSERTIONS AND WHILE-LOOPS http://www.cs.cornell.edu/courses/cs0/20sp/labs/lab0.pdf. Preliminaries This lab gives you practice with writing loops using invariant-based reasoning. Invariants

More information

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28)   First Name: Last Name: NetID: CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) http://www.cs.cornell.edu/courses/cs1110/2016sp/labs/lab01/lab01.pdf First Name: Last Name: NetID: Goals. Learning a computer language is a lot like learning

More information

isinstance and While Loops

isinstance and While Loops CS 1110: Introduction to Computing Using Python Lecture 20 isinstance and While Loops [Andersen, Gries, Lee, Marschner, Van Loan, White] Announcements A4: Due 4/20 at 11:59pm Should only use our str method

More information

CS 1110 Prelim 2 November 12th, 2015

CS 1110 Prelim 2 November 12th, 2015 CS 1110 Prelim 2 November 12th, 2015 This 90-minute exam has 6 questions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need

More information

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS CS 1110, LAB 2: ASSIGNMENTS AND STRINGS http://www.cs.cornell.edu/courses/cs1110/2014fa/labs/lab02.pdf First Name: Last Name: NetID: The purpose of this lab is to get you comfortable with using assignment

More information

Assignment 3: Due Friday Mar 4 at 6pm on CMS Updates in orange/red; last update 12:10pm Sun Feb 28

Assignment 3: Due Friday Mar 4 at 6pm on CMS Updates in orange/red; last update 12:10pm Sun Feb 28 CS1110 Spring 2016 Assignment 3: Due Friday Mar 4 at 6pm on CMS Updates in orange/red; last update 12:10pm Sun Feb 28 You must work either on your own or with one partner. If you work with a partner, you

More information

CS Boolean Statements and Decision Structures. Week 6

CS Boolean Statements and Decision Structures. Week 6 CS 17700 Boolean Statements and Decision Structures Week 6 1 Announcements Midterm 1 is on Feb 19 th, 8:00-9:00 PM in PHYS 114 and PHYS 112 Let us know in advance about conflicts or other valid makeup

More information

CS 1110 Prelim 1 March 7th, 2013

CS 1110 Prelim 1 March 7th, 2013 Last Name: First Name: Cornell NetID, all caps: Circle your lab: Tu 12:20 Tu 1:25 Tu 2:30 Tu 3:35 W 12:20 W 1:25 W 2:30 W 3:35 CS 1110 Prelim 1 March 7th, 2013 It is a violation of the Academic Integrity

More information

CS Lecture 18: Card Tricks. Announcements. Slides by D. Gries, L. Lee, S. Marschner, W. White

CS Lecture 18: Card Tricks. Announcements. Slides by D. Gries, L. Lee, S. Marschner, W. White CS 1110 Lecture 18: Card Tricks Announcements Slides by D. Gries, L. Lee, S. Marschner, W. White Quick poker primer Basic (straight) version: 5 random cards in your hand 2 of same rank: pair (e.g., 3C

More information

CS 1110, LAB 2: FUNCTIONS AND ASSIGNMENTS

CS 1110, LAB 2: FUNCTIONS AND ASSIGNMENTS CS 1110, LAB 2: FUNCTIONS AND ASSIGNMENTS http://www.cs.cornell.edu/courses/cs1110/2017fa/labs/lab2/ First Name: Last Name: NetID: The purpose of this lab is to get you comfortable with using assignment

More information

CMSC201 Computer Science I for Majors

CMSC201 Computer Science I for Majors CMSC201 Computer Science I for Majors Lecture 13 Functions Prof. Jeremy Dixon Based on concepts from: http://mcsp.wartburg.edu/zelle/python/ppics2/index.html Last Class We Covered Midterm exam Comments?

More information

Sorting and Searching

Sorting and Searching CS 1110: Introduction to Computing Using Pyton Lecture 23 Sorting and Searcing [Andersen, Gries, Lee, Marscner, Van Loan, Wite] Announcements Final Exam conflicts due tonigt at 11:59pm Final Exam review

More information

PREPARING FOR PRELIM 2

PREPARING FOR PRELIM 2 PREPARING FOR PRELIM 2 CS 1110: FALL 2012 This handout explains what you have to know for the second prelim. There will be a review session with detailed examples to help you study. To prepare for the

More information

Assignment 3: Due Thursday Feb 26 at 11pm

Assignment 3: Due Thursday Feb 26 at 11pm CS1110 Spring 2015 Assignment 3: Due Thursday Feb 26 at 11pm You must work either on your own or with one partner. If you work with a partner, you and your partner must first register as a group in CMS

More information

CS 1110 Prelim 2 November 12th, 2015

CS 1110 Prelim 2 November 12th, 2015 CS 1110 Prelim 2 November 12th, 2015 This 90-minute exam has 6 questions worth a total of 100 points. Scan the whole test before starting. udget your time wisely. Use the back of the pages if you need

More information

PREPARING FOR THE FINAL EXAM

PREPARING FOR THE FINAL EXAM PREPARING FOR THE FINAL EXAM CS 1110: FALL 2012 This handout explains what you have to know for the final exam. Most of the exam will include topics from the previous two prelims. We have uploaded the

More information

CS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:

CS 1110, LAB 3: MODULES AND TESTING   First Name: Last Name: NetID: CS 1110, LAB 3: MODULES AND TESTING http://www.cs.cornell.edu/courses/cs11102013fa/labs/lab03.pdf First Name: Last Name: NetID: The purpose of this lab is to help you better understand functions, and to

More information

Lecture 7. Strings & Stepwise Refinement

Lecture 7. Strings & Stepwise Refinement Lecture 7 Strings & Stepwise Refinement Announcements for This Lecture pp. 175 181 Readings Sections 2.5, 3.1.2-3.1.3 (optional) PLive p. 2-5 Assignments Assignment 1 due tonight Before Midnight!!! Will

More information

Acct. balance Acct. balance 50 25

Acct. balance Acct. balance 50 25 Last Name: First Name: Cornell NetID, all caps: CS 1110 Regular Prelim 1 Solutions March 2017 1. Object Diagramming and Terminology. (a) [8 points] Suppose there is a class Acct defined in file a2.py where

More information

Lecture 8. Reviewing Methods; Wrapper Classes

Lecture 8. Reviewing Methods; Wrapper Classes Lecture 8 Reviewing Methods; Wrapper Classes Announcements for This Lecture Readings Sections 2.5 and 5.1 PLive 5-1 and 5-2 Assignments Assignment 2 due Tuesday Turn in during class Not accepting on CMS

More information

CS 1110, Spring 2018: Prelim 1 study guide Prepared Tuesday March 6, 2018

CS 1110, Spring 2018: Prelim 1 study guide Prepared Tuesday March 6, 2018 CS 1110, Spring 2018: Prelim 1 study guide Prepared Tuesday March 6, 2018 Administrative info Time and locations of the regular exam listed at http://www.cs.cornell.edu/courses/cs1110/2018sp/exams What

More information

CS1110 Lab 6 (Mar 17-18, 2015)

CS1110 Lab 6 (Mar 17-18, 2015) CS1110 Lab 6 (Mar 17-18, 2015) First Name: Last Name: NetID: The lab assignments are very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness does not matter.)

More information

CS 1110 Prelim 2 November 6th, 2012

CS 1110 Prelim 2 November 6th, 2012 CS 1110 Prelim 2 November 6th, 2012 This 90-minute exam has 6 questions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need

More information

CS 100 Spring Lecture Notes 3/8/05 Review for Exam 2

CS 100 Spring Lecture Notes 3/8/05 Review for Exam 2 CS 100 Spring 2005 Lecture Notes 3/8/05 Review for Exam 2 The second exam is Thursday, March 10. It will cover topics from Homework 2 through Homework 4, including anything pertaining to binary representation.

More information

CS Prelim 2 Review Fall 2012

CS Prelim 2 Review Fall 2012 CS 1110 Prelim 2 Review Fall 2012 Exam Info Prelim 1: 7:30 9:00PM, Tuesday, November 6th Last name A P in Kennedy 1116 Last name R T in Warren 131 Last name U Z in Warren 231 To help you study: Study guides,

More information

CS 1110 Regular Prelim 1, March 14th, 2017

CS 1110 Regular Prelim 1, March 14th, 2017 Last Name: First Name: Cornell NetID, all caps: CS 1110 Regular Prelim 1, March 14th, 2017 This 90-minute exam has 9 questions worth a total of 104 points. You may tear the pages apart; we have a stapler

More information

RECURSION (CONTINUED)

RECURSION (CONTINUED) RECURSION (CONTINUED) Lecture 9 CS2110 Spring 2018 Prelim two weeks from today: 13 March. 1. Visit Exams page of course website, check what time your prelim is, complete assignment P1Conflict ONLY if necessary.

More information

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python. Raspberry Pi Learning Resources Turtle Snowflakes Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python. How to draw with Python Turtle 1. To begin, you will

More information

61A Lecture 7. Monday, September 16

61A Lecture 7. Monday, September 16 61A Lecture 7 Monday, September 16 Announcements Homework 2 due Tuesday at 11:59pm Project 1 due Thursday at 11:59pm Extra debugging office hours in Soda 405: Tuesday 6-8, Wednesday 6-7, Thursday 5-7 Readers

More information

CS 1110 Prelim 1 October 12th, 2017

CS 1110 Prelim 1 October 12th, 2017 CS 1110 Prelim 1 October 12th, 2017 This 90-minute exam has 6 uestions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need more

More information

CS 1110 Prelim 2 November 13th, 2014

CS 1110 Prelim 2 November 13th, 2014 CS 1110 Prelim 2 November 13th, 2014 This 90-minute exam has 5 questions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need

More information

CS Lecture 26: Grab Bag. Announcements

CS Lecture 26: Grab Bag. Announcements CS 1110 Lecture 26: Grab Bag Announcements The End is Nigh! 1. Next (last) lecture will be recap and final exam review 2. A5 due Wednesday night 3. Final exam 7pm Thursday May 15 in Barton Hall (East section)

More information

CS 1110, LAB 12: SEQUENCE ALGORITHMS First Name: Last Name: NetID:

CS 1110, LAB 12: SEQUENCE ALGORITHMS   First Name: Last Name: NetID: CS 1110, LAB 12: SEQUENCE ALGORITHMS http://www.cs.cornell.edu/courses/cs1110/2014fa/labs/lab12.pdf First Name: Last Name: NetID: This last lab is extremely important. It helps you understand how to construct

More information

Lecture 15. More Recursion

Lecture 15. More Recursion Lecture 15 More Recursion Announcements for This Lecture Prelim 1 Prelim 1 back today! Access in Gradescope Solution posted in CMS Mean: 71, Median: 74 Testing was horrible What are letter grades? A: 80

More information

CS 1110 Prelim 2 November 10th, 2016

CS 1110 Prelim 2 November 10th, 2016 CS 1110 Prelim 2 November 10th, 2016 This 90-minute exam has 5 questions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need

More information

CS Prelim 2 Review Fall 2017

CS Prelim 2 Review Fall 2017 CS 1110 Prelim 2 Review Fall 2017 Exam Info Prelim 2: 7:30 9:00PM, Thursday, Nov. 9th Last name A J in Uris G01 Last name K Z in Statler Auditorium SDS Students will get an e-mail To help you study: Study

More information

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Introduction to Python Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas If you have your own PC, download and install a syntax-highlighting text editor and Python

More information