Lecture 4: Defining Functions
|
|
- Deborah Miles
- 6 years ago
- Views:
Transcription
1 Lecture 4: Defining Functions (Ch ) CS 0 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]
2 Things to Do Before Next Class Readings: Sections 8., 8.2, 8.4, 8.5, first paragraph of 8.9 Labs: Go to Lab! (Lab 2 is this week) Get Credit for Lab : can be checked off during Tuesday's consulting hours 4:30-9:30 in the ACCEL lab cannot be checked off after 3:45pm Wednesday check online if you received credit: 208sp/labs/index.php 2
3 Check out Piazza 3
4 4
5 5
6
7 From last time: Function Calls Function expressions have the form fun(x,y, ) Examples (math functions that work in Python): round(2.34) max(a+3,24) function name argument 7
8 From last time: Modules Modules provide extra functions, variables Access them with the import command Example: module math >>> import math >>> math.cos(2.0) >>> math.pi
9 From last time: Modules Module Text # my_module.py """This is a simple module. It shows how modules work""" Interactive Python >>> import my_module >>> my_module.x 9 x = +2 x = 3*x We discussed how to make module variables Have not covered how to make functions 9
10 simple_math.py >>> import simple_math >>> simple_math.increment() 2 >>> simple_math. increment(2) 3 0
11 Anatomy of a Function Definition name parameters def increment(n): Function Header """Returns: the value of n+""" return n+ Docstring Specification Statements to execute when called also called Function Body The vertical line indicates indentation Use vertical lines when you write Python on exams so we can see indentation
12 The return Statement Passes a value from the function to the caller Format: return <expression> Any statements after return are ignored Optional (if absent, special value None will be sent back) 2
13 Function Calls vs. Definitions Function Call Command to do the function Function Definition Defines what function does >>> simple_math.increment(23) 24 >>> argument to assign to n def increment(n): return n+ declaration of parameter n Parameter: variable that is listed within the parentheses of a function header. Argument: a value to assign to the function parameter when it is called 3
14 Using simple_math.py Module Text Interactive Python # simple_math.py Python skips >>> import simple_math """module with two simple math functions""" Python skips def increment(n): """Returns: n+""" return n+ Python learns the function definition Python skips everything inside the function Repeat for all functions in module 4
15 Using simple_math.py Module Text # simple_math.py """module with two simple math functions""" def increment(n): """Returns: n+""" return n+ Interactive Python >>> import simple_math >>> simple_math.increment(23) Now Python executes the function body Python knows what this is! 5
16 Using simple_math.py Module Text # simple_math.py """module with two simple math functions""" Interactive Python >>> import simple_math >>> simple_math.increment(23) def increment(n): """Returns: n+""" return n+ 6
17 Using simple_math.py Module Text # simple_math.py """module with two simple math functions""" Interactive Python >>> import simple_math >>> simple_math.increment(23) 24 def increment(n): """Returns: n+""" return n+ 7
18 Understanding How Functions Work We will draw pictures to show what is in memory Function Frame: Representation of function call Draw parameters as variables (named boxes) Number of statement in the function body to execute next Starts with function name instruction counter parameters local variables (later in lecture) Note: slightly different than in the book (3.9) Please do it this way. 8
19 Example: get_feet >>> import height >>> height.get_feet(68) def get_feet(height_in_inches): return height_in_inches // INCHES_PER_FOOT 9
20 Example: get_feet(68) PHASE : Set up call frame next line to execute. Draw a frame for the call 2. Assign the argument value to the parameter (in frame) 3. Indicate next line to execute get_feet height_in_inches 68 def get_feet(height_in_inches): return height_in_inches // INCHES_PER_FOOT 20
21 Example: get_feet(68) PHASE 2: Execute function body Return statement creates a special variable for result get_feet height_in_inches 68 RETURN 5 def get_feet(height_in_inches): return height_in_inches // INCHES_PER_FOOT 2
22 Example: get_feet(68) PHASE 2: Execute function body The return terminates; no next line to execute get_feet height_in_inches 68 RETURN 5 def get_feet(height_in_inches): return height_in_inches // INCHES_PER_FOOT 22
23 Example: get_feet(68) PHASE 3: Erase call frame get_feet height_in_inches 68 RETURN 5 def get_feet(height_in_inches): return height_in_inches // INCHES_PER_FOOT 23
24 Example: get_feet(68) PHASE 3: Erase call frame But don t actually erase on an exam ERASE WHOLE FRAME def get_feet(height_in_inches): return height_in_inches // INCHES_PER_FOOT 24
25 Local Variables () Call frames can make local variables >>> import room_numbers >>> room_numbers.lab_rooms() lab_rooms def lab_rooms(): 2 red_room = 235 orange_room =
26 Local Variables (2) Call frames can make local variables >>> import room_numbers >>> room_numbers.lab_rooms() lab_rooms 2 def lab_rooms(): red_room red_room = 235 orange_room =
27 Local Variables (3) Call frames can make local variables >>> import room_numbers >>> room_numbers.lab_rooms() lab_rooms def lab_rooms(): red_room red_room = 235 orange_room = 236 orange_room 236 RETURN NONE 27
28 Local Variables (4) Call frames can make local variables >>> import room_numbers >>> room_numbers.lab_rooms() 2 def lab_rooms(): red_room = 235 orange_room = 236 ERASE WHOLE FRAME Variables are gone! This function is useless. 28
29 Exercise Time 2 3 Function Definition def foo(a,b): x = a y = b return x*y+y >>> foo(3,4) Function Call What does the frame look like at the start? 29
30 Which One is Closest to Your Answer? A: B: foo a 3 b 4 foo a 3 b 4 x a C: D: foo a 3 b 4 foo a 3 b 4 x 3 x y 30
31 Exercise Time 2 3 Function Definition def foo(a,b): x = a y = b return x*y+y >>> foo(3,4) B: Function Call foo a 3 b 4 What is the next step? 3
32 Which One is Closest to Your Answer? A: B: foo 2 a 3 b 4 foo a 3 b 4 x 3 C: D: foo 2 a 3 b 4 x 3 foo 2 a 3 b 4 x 3 y 32
33 Exercise Time 2 3 Function Definition def foo(a,b): x = a y = b return x*y+y >>> foo(3,4) C: Function Call foo 2 a 3 b 4 x 3 What is the next step? 33
34 Exercise Time 2 3 Function Definition def foo(a,b): x = a y = b return x*y+y >>> foo(3,4) Function Call foo 3 a 3 b 4 x 3 y 4 What is the next step? 34
35 Which One is Closest to Your Answer? A: B: foo 3 foo RETURN 6 a 3 b 4 x 3 y 4 3 RETURN 6 C: D: foo a 3 b 4 x 3 y 4 RETURN 6 ERASE THE FRAME 35
36 Exercise Time 2 3 Function Definition def foo(a,b): x = a y = b return x*y+y >>> foo(3,4) C: foo Function Call a 3 b 4 x 3 y 4 RETURN 6 What is the next step? 36
37 Exercise Time 2 3 Function Definition def foo(a,b): x = a y = b return x*y+y >>> foo(3,4) >>> 6 Function Call ERASE THE FRAME 37
38 Function Access to Global Space All function definitions are in some module Call can access global space for that module math.cos: global for math height.get_feet uses global for height But cannot change values Assignment to a global makes a new local variable! Global Space (for scope_example.py) change_a a 3.5 # scope_example.py """Show how globals work""" a = 4 # global space def change_a(): a a = 3.5 # local variable return a 4 38
39 Function Access to Global Space All function definitions are in some module Call can access global space for that module math.cos: global for math height.get_feet uses global for height But cannot change values Assignment to a global makes a new local variable! Global Space (for scope_example.py) a 4 get_a # scope_example.py """Show how globals work""" a = 4 # global space def get_a(): return a # returns global 39
40 Call Frames and Global Variables The specification is a lie: 2 def swap(a,b): """Swap global a & b""" tmp = a a = b b = tmp Global Variables a b 2 Call Frame 3 swap >>> a = >>> b = 2 >>> swap(a,b) a b 2 40
41 Call Frames and Global Variables The specification is a lie: 2 3 def swap(a,b): """Swap global a & b""" tmp = a a = b b = tmp >>> a = >>> b = 2 >>> swap(a,b) Global Variables a b 2 Call Frame swap 2 a b 2 tmp 4
42 Call Frames and Global Variables The specification is a lie: 2 3 def swap(a,b): """Swap global a & b""" tmp = a a = b b = tmp >>> a = >>> b = 2 >>> swap(a,b) Global Variables a b 2 Call Frame swap 3 x a 2 b 2 tmp 42
43 Call Frames and Global Variables The specification is a lie: 2 3 def swap(a,b): """Swap global a & b""" tmp = a a = b b = tmp >>> a = >>> b = 2 >>> swap(a,b) Global Variables a b 2 Call Frame swap x a 2 b 2 tmp x 43
44 Call Frames and Global Variables The specification is a lie: 2 3 def swap(a,b): """Swap global a & b""" tmp = a a = b b = tmp >>> a = >>> b = 2 >>> swap(a,b) Global Variables a b 2 Call Frame ERASE THE FRAME 44
45 Call Frames and Global Variables The specification is a lie: 2 3 def swap(a,b): """Swap global a & b""" tmp = a a = b b = tmp >>> a = >>> b = 2 >>> swap(a,b) Global Variables a b 2 Call Frame THIS FUNCTION DOES NOT SWAP ERASE THE FRAME the global a and global b 45
46 Visualizing Frames: The Python Tutor 46
47 More Exercises Module Text Interactive Python # my_module.py def foo(x): return x+ >>> import my_module >>> my_module.x What does Python give me? x = +2 x = 3*x A: 9 CORRECT B: 0 C: D: Nothing E: Error 47
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 informationLecture 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 informationLecture 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 informationLecture 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 informationLecture 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 informationLecture 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 informationLecture 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 informationConditionals & 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 informationLecture 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 informationLecture 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 informationCS1110. 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 informationLecture 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 informationCS1110. 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 informationLecture 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 informationLecture 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 informationLecture 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 informationLecture 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 informationCS 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 informationLecture 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 informationLecture 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 informationCS 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 informationLecture 9: Memory in Python
http://www.cs.cornell.edu/courses/cs1110/2018sp 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]
More informationLecture 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 informationLecture 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 informationLecture 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 informationIteration 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 informationLecture 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 informationCS 1110, LAB 13: SEQUENCE ALGORITHMS
CS 1110, LAB 13: SEQUENCE ALGORITHMS http://www.cs.cornell.edu/courses/cs1110/2017fa/labs/lab13/ First Name: Last Name: NetID: This final lab of the course helps you practice with more complicated invariants
More informationPREPARING 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 informationLecture 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 informationCS 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 informationCS 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 information61A Lecture 7. Monday, September 15
61A Lecture 7 Monday, September 15 Announcements Homework 2 due Monday 9/15 at 11:59pm Project 1 deadline extended, due Thursday 9/18 at 11:59pm! Extra credit point if you submit by Wednesday 9/17 at 11:59pm
More informationLecture 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 informationLecture 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 informationCS 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 informationCS 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 informationCS 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 informationLecture 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 informationLecture 3. Strings, Functions, & Modules
Lecture 3 Strings, 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
More informationLecture 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 informationLecture 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 informationCS1 Lecture 4 Jan. 23, 2019
CS1 Lecture 4 Jan. 23, 2019 First graded discussion sections this week yesterday/today 10 DS assignments worth 2 points each everyone gets one free 2-pointer. I.e. your lowest DS grade will be replaced
More information61A 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 informationCS 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 informationCS 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 informationCS1 Lecture 3 Jan. 18, 2019
CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due
More informationCS 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 information61A Lecture 2. Wednesday, September 4, 2013
61A Lecture 2 Wednesday, September 4, 2013 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions:
More informationisinstance 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 informationCS1 Lecture 4 Jan. 24, 2018
CS1 Lecture 4 Jan. 24, 2018 First homework due Mon., 9:00am Meet specifications precisely. Functions only. Use a file editor! Don t type functions/long sections of code directly into Python interpreter.
More informationCS1110. 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 informationLecture 1. Course Overview Types & Expressions
Lecture 1 Course Overview Types & Expressions CS 1110 Spring 2012: Walker White Outcomes: Basics of (Java) procedural programming Usage of assignments, conditionals, and loops. Ability to write recursive
More informationCS 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} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.
Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.
More informationCS1 Lecture 15 Feb. 18, 2019
CS1 Lecture 15 Feb. 18, 2019 HW4 due Wed. 2/20, 5pm Q2 and Q3: it is fine to use a loop as long as the function is also recursive. Exam 1, Thursday evening, 2/21, 6:30-8:00pm, W290 CB You must bring ID
More informationCS 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 information4. Modules and Functions
4. Modules and Functions The Usual Idea of a Function Topics Modules Using import Using functions from math A first look at defining functions sqrt 9 3 A factory that has inputs and builds outputs. Why
More informationCS 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 informationUnit 10: Data Structures CS 101, Fall 2018
Unit 10: Data Structures CS 101, Fall 2018 Learning Objectives After completing this unit, you should be able to: Define and give everyday examples of arrays, stacks, queues, and trees. Explain what a
More informationCS1 Lecture 3 Jan. 22, 2018
CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow
More informationPREPARING 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 informationSAMS Programming A/B. Lecture #1 Introductions July 3, Mark Stehlik
SAMS Programming A/B Lecture #1 Introductions July 3, 2017 Mark Stehlik Outline for Today Overview of Course A Python intro to be continued in lab on Wednesday (group A) and Thursday (group B) 7/3/2017
More informationCOMP1730/COMP6730 Programming for Scientists. Functions
COMP1730/COMP6730 Programming for Scientists Functions Lecture outline * Function definition. * Function calls & order of evaluation. * Assignments in functions; local variables. * Function testing. Functions
More informationCS 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 informationCIS192: Python Programming
CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms
More informationUNIT 2B An Introduction to Programming. Announcements
UNIT 2B An Introduction to Programming 1 Announcements Tutoring help on Mondays 8:30 11:00 pm in the Mudge Reading Room Extra help session Fridays 12:00 2:00 pm in GHC 4122 Academic integrity forms Always
More informationPREPARING 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 informationLecture 1. Course Overview, Python Basics
Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures and Labs are at fire-code capacity We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are
More informationUse the Associative Property of Multiplication to find the product.
3-1 1. The Associative Property of Multiplication states factors can be grouped differently and the product remains the same. Changing the grouping of the factors changes the factors that are multiplied
More information61A Lecture 6. Monday, February 2
61A Lecture 6 Monday, February 2 Announcements Homework 2 due Monday 2/2 @ 11:59pm Project 1 due Thursday 2/5 @ 11:59pm Project party on Tuesday 2/3 5pm-6:30pm in 2050 VLSB Partner party on Wednesday 2/4
More informationLecture 13. For-Loops
Lecture 3 For-Loops Announcements for This Lecture Reading Assignments/Lab Today: Chapters 8, 0 Thursday: Chapter Prelim, 0/ 5:5 OR 7:30 Material up to TUESDAY Study guide is posted Times/rooms by last
More informationCS1 Lecture 13 Feb. 13, 2019
CS1 Lecture 13 Feb. 13, 2019 Exam 1, Thursday evening, 2/21, 6:30-8:00pm, W290 CB Email about make-ups will be sent tomorrow HW4 Q1 available. Q2 Q4 tomorrow. For Q1 only, Academic Honesty policy does
More information61A Lecture 2. Friday, August 28, 2015
61A Lecture 2 Friday, August 28, 2015 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions: max
More informationCOMP519 Web Programming Lecture 20: Python (Part 4) Handouts
COMP519 Web Programming Lecture 20: Python (Part 4) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents
More informationCS1 Lecture 15 Feb. 19, 2018
CS1 Lecture 15 Feb. 19, 2018 HW4 due Wed. 2/21, 5pm (changed from original 9am so people in Wed. disc. sections can get help) Q2: find *any* solution. Don t try to find the best/optimal solution or all
More informationLecture 8. Conditionals & Control Flow
Lecture 8 Conditionals & Control Flow Announcements For This Lecture Readings Sections 5.1-5.7 today Chapter 4 for Tuesday Assignment 2 Posted Today Written assignment Do while revising A1 Assignment 1
More informationCS 102 Lab 3 Fall 2012
Name: The symbol marks programming exercises. Upon completion, always capture a screenshot and include it in your lab report. Email lab report to instructor at the end of the lab. Review of built-in functions
More informationCS 115 Exam 2 (Section 1) Fall 2017 Thu. 11/09/2017
CS 115 Exam 2 (Section 1) Fall 2017 Thu. 11/09/2017 Name: Rules and Hints You may use one handwritten 8.5 x 11 cheat sheet (front and back). This is the only additional resource you may consult during
More informationHow To Think Like A Computer Scientist, chapter 3; chapter 6, sections
6.189 Day 3 Today there are no written exercises. Turn in your code tomorrow, stapled together, with your name and the file name in comments at the top as detailed in the Day 1 exercises. Readings How
More informationCS 051 Homework Laboratory #2
CS 051 Homework Laboratory #2 Dirty Laundry Objective: To gain experience using conditionals. The Scenario. One thing many students have to figure out for the first time when they come to college is how
More informationCS 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 informationCS 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 informationLecture 1. Course Overview, Python Basics
Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures are at fire-code capacity. We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are allowed
More informationCME 193: Introduction to Scientific Python Lecture 1: Introduction
CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements
More informationCS 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 informationName Section: M/W T/TH Number Definition Matching (8 Points)
Name Section: M/W T/TH Number Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Iteration Counter Event Counter Loop Abstract Step
More informationS206E Lecture 19, 5/24/2016, Python an overview
S206E057 Spring 2016 Copyright 2016, Chiu-Shui Chan. All Rights Reserved. Global and local variables: differences between the two Global variable is usually declared at the start of the program, their
More informationCS64 Week 5 Lecture 1. Kyle Dewey
CS64 Week 5 Lecture 1 Kyle Dewey Overview More branches in MIPS Memory in MIPS MIPS Calling Convention More Branches in MIPS else_if.asm nested_if.asm nested_else_if.asm Memory in MIPS Accessing Memory
More information61A Lecture 9. Friday, September 20
61A Lecture 9 Friday, September 20 Announcements Midterm 1 is on Monday 9/23 from 7pm to 9pm 2 review sessions on Saturday 9/21 2pm-4pm and 4pm-6pm in 1 Pimentel HKN review session on Sunday 9/22 from
More informationAnnouncements. Last modified: Fri Sep 8 00:59: CS61B: Lecture #7 1
Announcements Sign-ups for weekly group tutoring offered by the course tutors have been released! Form will close on Saturday, 9/9, at 11:59PM. You will receive room and time assignments on Sunday via
More informationCS2102, B15 Exam 2. Name:
CS2102, B15 Exam 2 Name: You have 50 minutes to complete the problems on the following pages. There should be sufficient space provided for your answers. If a problem asks you to create an interface, you
More informationSemester 2, 2018: Lab 1
Semester 2, 2018: Lab 1 S2 2018 Lab 1 This lab has two parts. Part A is intended to help you familiarise yourself with the computing environment found on the CSIT lab computers which you will be using
More informationModule 01: Introduction to Programming in Python
Module 01: Introduction to Programming in Python Topics: Course Introduction Introduction to Python basics Readings: ThinkP 1,2,3 1 Finding course information https://www.student.cs.uwaterloo.ca/~cs116/
More informationCSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic
CSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic Announcements: Test 1 Information Test 1 will be held Thursday, Sept 20th, 2018 from 6-7:50pm Students will be randomly
More informationCS1 Lecture 5 Jan. 25, 2019
CS1 Lecture 5 Jan. 25, 2019 HW1 due Monday, 9:00am. Notes: Do not write all the code at once before starting to test. Take tiny steps. Write a few lines test... add a line or two test... add another line
More informationSorting 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 informationProblem 1 (a): List Operations
Problem 1 (a): List Operations Task 1: Create a list, L1 = [1, 2, 3,.. N] Suppose we want the list to have the elements 1, 2, 10 range(n) creates the list from 0 to N-1 But we want the list to start from
More informationCS 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 informationLecture 1: Introduction, Types & Expressions
http://www.cs.cornell.edu/courses/cs1110/2018sp Lecture 1: Introduction, Types & Expressions (Chapter 1, Section 2.6) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L.
More information