CS1110. Lecture 6: Function calls

Similar documents
CS1110. Lecture 6: Function calls

CS 1110: Introduction to Computing Using Python Lists and Sequences

Lecture 26: Sorting CS 1110 Introduction to Computing Using Python

Lecture 7. Memory in Python

Conditionals & Control Flow

Lecture 10: Lists and Sequences

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

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

Lecture 4: Defining Functions

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

Lecture 6: Specifications & Testing

Lecture 2: Variables & Assignments

Lecture 24: Loop Invariants

Lecture 10. Memory in Python

CS Lecture 19: Loop invariants

CS 1110: Introduction to Computing Using Python Loop Invariants

Lecture 4. Defining Functions

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

Lecture 9. Memory and Call Stacks

Iteration and For Loops

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

Lecture 19: Subclasses & Inheritance (Chapter 18)

Lecture 4. Defining Functions

CS 1110, LAB 3: STRINGS; TESTING

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

Stepwise Refinement. Lecture 12 COP 3014 Spring February 2, 2017

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

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

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

Lecture 11: Iteration and For-Loops

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

Lecture 9: Memory in Python

Lecture 17: Classes (Chapter 15)

Lecture 20: While Loops (Sections 7.3, 7.4)

Lecture 12. Lists (& Sequences)

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

CS 1110, LAB 13: SEQUENCE ALGORITHMS

isinstance and While Loops

Lecture 5. Defining Functions

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

Lecture 18: Using Classes Effectively (Chapter 16)

CS Prelim 1 Review Fall 2016

Announcements for this Lecture

Lecture 5: Strings

Lecture 17: Classes (Chapter 15)

Lecture 13. For-Loops

CS Prelim 1 Review Fall 2017

COMP1730/COMP6730 Programming for Scientists. Functions

Lecture 8. Conditionals & Control Flow

COMP s1 Lecture 1

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

PREPARING FOR PRELIM 1

Announcements - Grades UBLearns grades just updated Monday, March 28 th (11:00am). Please check grades.

CS Prelim 1 Review Fall 2018

What is an algorithm?

DECOMPOSITION, ABSTRACTION, FUNCTIONS

6.01, Spring Semester, 2008 Assignment 3, Issued: Tuesday, February 19 1

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

CS150 - Assignment 5 Data For Everyone Due: Wednesday Oct. 16, at the beginning of class

CpSc 1111 Lab 9 2-D Arrays

Announcements for This Lecture

Lecture 3: Functions & Modules

61A Lecture 7. Monday, September 15

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

CSCA08 Winter 2018 Week 2: Variables & Functions. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough

. As x gets really large, the last terms drops off and f(x) ½x

CS1110. Lecture 1: Final review session. Review materials See website for a version of last year s final with conventions redone to match this year.

Announcements for This Lecture

Lecture 13. For-Loops

Before We Begin. Introduction to Computer Use II. Overview (1): Winter 2006 (Section M) CSE 1530 Winter Bill Kapralos.

Lecture 14. Nested Lists and Dictionaries

CS Prelim 1 Review Fall 2013

61A LECTURE 1 FUNCTIONS, VALUES. Steven Tang and Eric Tzeng June 24, 2013

VSCode: Open Project -> View Terminal -> npm run pull -> npm start. Lecture 16

type name(arg1, arg2,...) { body return }

6.00 Introduction to Computer Science and Programming Fall 2008

CS 1110, LAB 2: FUNCTIONS AND ASSIGNMENTS

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

CS1110 Lab 6 (Mar 17-18, 2015)

Interlude. Why Object Oriented Programming?

Contact No office hours, but is checked multiple times daily. - Specific questions/issues, particularly conceptual

Lists in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #10

Revising CS-M41. Oliver Kullmann Computer Science Department Swansea University. Linux Lab Swansea, December 13, 2011.

Lecture 22. While Loops

15-780: Problem Set #3

Basic Data Types and Operators CS 8: Introduction to Computer Science, Winter 2019 Lecture #2

University of Waterloo CS240, Winter 2010 Assignment 2

Python Lists and Dictionaries CS 8: Introduction to Computer Science, Winter 2019 Lecture #13

CS Prelim 1 Review Fall 2012

UNIT 2B An Introduction to Programming. Announcements

Lecture 8. Reviewing Methods; Wrapper Classes

Welcome to CS 115 (Winter 2019)

Top Down Breaking a Problem Down

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

More Examples Using Lists Tuples and Dictionaries in Python CS 8: Introduction to Computer Science, Winter 2018 Lecture #11

Python Lists 2 CS 8: Introduction to Computer Science Lecture #9

CS 051 Homework Laboratory #2

COMP519 Web Programming Lecture 20: Python (Part 4) Handouts

Lecture 20. Subclasses & Inheritance

CMSC 201 Spring 2016 Lab 12 Classes and Objects

Transcription:

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! Assignment 1 is out. The first submission is due February 24. CMS will show an extension, but this is only for your corrected revisions later on. No labs next week due to Winter Break. Many office hours are available. See the course website. Slides by D. Gries, L. Lee, S. Marschner, W. White

How Do Functions Work? function call print add_em(3, 4) 2. Assign arguments to arguments def add_em(x, y): return x + y function name add_em x 3 y 4 call frame Return value: 7

How Do Functions Work? function call print add_em(3, 4) arguments def add_em(x, y): 1 sum = x + y 2 return sum 2. Assign arguments to statement numbers function name add_em:1 x 3 y 4 sum local variables 7 call frame 2 program counter Return value: 7

a = 1 b = 2 swap(a, b) 2. Assign arguments to with print, use commas to print several values def swap(x, y): 1 x = y 2 y = x 3 print 'x, y:', x, y Execute this call on paper. What gets printed out? A: x, y: 1 2 B: x, y: 2 1 C: x, y: 2 2 D: x, y: 1 1 E: I don t know

a = 1 b = 2 swap(a, b) arguments module (global) variables a b 1 2 def swap(x, y): 1 x = y 2 y = x 3 print 'x, y:', x, y 2. Assign arguments to swap:1 program counter x y

a = 1 b = 2 swap(a, b) print 'a, b:', a, b arguments module (global) variables a b 1 2 def swap(x, y): 1 t = x 2 x = y 3 y = t 4 print 'x, y:', x, y 2. Assign arguments to Execute this call on paper. What gets printed out? A: x, y: 1 2 B: x, y: 2 1 C: x, y: 2 2 D: x, y: 1 1 E: I don t know

a = 1 b = 2 swap(a, b) print 'a, b:', a, b arguments module (global) variables a b 1 2 def swap(x, y): 1 t = x 2 x = y 3 y = t 4 print 'x, y:', x, y 2. Assign arguments to Execute this call on paper. What gets printed out? A: a, b: 1 2 B: a, b: 2 1 C: a, b: 2 2 D: a, b: 1 1 E: I don t know

a = 1 b = 2 swap(a, b) print 'a, b:', a, b arguments module (global) variables a b 1 2 def swap(x, y): 1 t = x 2 x = y 3 y = t 4 print 'x, y:', x, y 2. Assign arguments to local variables program counter swap:1 x y t

import point p = point.point(1,2,3) q = point.point(3,4,5) swap_x(p, q) print 'p:', p print 'q:', q def swap_x(p, q): 1 t = p.x 2 p.x = q.x 3 q.x = t Execute this code on paper. You will draw 2 objects and a frame. What is in p.x at the end? A: 1 B: 2 C: 3 D: I don t know

import point p = point.point(1,2,3) q = point.point(3,4,5) swap_x(p, q) print 'p:', p print 'q:', q module (global) variables p q id1 id2 def swap_x(p, q): 1 t = p.x 2 p.x = q.x 3 q.x = t id1 Point id2 Point swap_x:1 x 1.0 x 3.0 p q y 2.0 y 4.0 t z 3.0 z 5.0

s lt_speed = 3e8 print g(3) def g(m): 1 E = f(m, lt_speed) 2 return E def f(x, y): 1 return x * (y**2) lt_speed 3 10 8 2. Assign arguments to g:1 m E f:1 x y parameter local variable

How to Draw Things variable object variable name old value value class identifier class name class name attributes methods function name : program counter module name local variables call frame

Online Python Tutor module (global) variables pythontutor.com type in whatever code you want controls for stepping through code output from print goes here frame for call of g frame for call of f