Lecture 4. Defining Functions
|
|
- Randall Mills
- 5 years ago
- Views:
Transcription
1 Lecture 4 Defining Functions
2 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 9/10, take it again If you are not aware of the quiz Go to Click Academic Integrity in side bar Read and take quiz in CMS 9/4/18 Defining Functions 2
3 Recall: Modules Modules provide extra functions, variables Example: math provides math.cos(), math.pi Access them with the import command Python provides a lot of them for us This Lecture: How to make modules Atom Editor to make a module Python to use the module Two different programs 9/4/18 Defining Functions 3
4 We Write Programs to Do Things Functions are the key doers Function Call Function Definition Command to do the function >>> plus(23) 24 >>> Defines what function does def plus(n): return n+1 Parameter: variable that is listed within the parentheses of a method header. Argument: a value to assign to the method parameter when it is called 9/4/18 Defining Functions 4
5 We Write Programs to Do Things Functions are the key doers Function Call Function Definition Command to do the function Defines what function does >>> plus(23) 24 >>> Function Header def plus(n): return n+1 Parameter: variable that is listed within the parentheses of a method header. Argument: a value to assign to the method parameter when it is called 9/4/18 Defining Functions 5
6 We Write Programs to Do Things Functions are the key doers Function Call Function Definition Command to do the function Defines what function does >>> plus(23) 24 >>> Function Header def plus(n): return n+1 Function Body (indented) Parameter: variable that is listed within the parentheses of a method header. Argument: a value to assign to the method parameter when it is called 9/4/18 Defining Functions 6
7 We Write Programs to Do Things Functions are the key doers Function Call Function Definition Command to do the function Defines what function does >>> plus(23) 24 >>> argument to assign to n Function Header def plus(n): declaration of parameter n return n+1 Function Body (indented) Parameter: variable that is listed within the parentheses of a method header. Argument: a value to assign to the method parameter when it is called 9/4/18 Defining Functions 7
8 Anatomy of a Function Definition name parameters def plus(n): """Returns the number n+1 Parameter n: number to add to Precondition: n is a number""" x = n+1 return x Function Header Docstring Specification Statements to execute when called 9/4/18 Defining Functions 8
9 Anatomy of a Function Definition name parameters def plus(n): """Returns the number n+1 Parameter n: number to add to Precondition: n is a number""" x = n+1 return x Function Header Docstring Specification Statements to execute when called The vertical line indicates indentation Use vertical lines when you write Python on exams so we can see indentation 9/4/18 Defining Functions 9
10 The return Statement Format: return <expression> Used to evaluate function call (as an expression) Also stops executing the function! Any statements after a return are ignored Example: temperature converter function def to_centigrade(x): """Returns: x converted to centigrade""" return 5*(x-32)/9.0 9/4/18 Defining Functions 10
11 A More Complex Example Function Definition def foo(a,b): """Return something Param a: number Param b: number""" x = a y = b return x*y+y >>> x = 2 >>> foo(3,4) Function Call x? What is in the box? 9/4/18 Defining Functions 11
12 A More Complex Example Function Definition def foo(a,b): """Return something Param a: number Param b: number""" x = a y = b return x*y+y >>> x = 2 >>> foo(3,4) Function Call x? What is in the box? A: 2 B: 3 C: 16 D: Nothing! E: I do not know 9/4/18 Defining Functions 12
13 A More Complex Example Function Definition def foo(a,b): """Return something Param a: number Param b: number""" x = a y = b return x*y+y >>> x = 2 >>> foo(3,4) Function Call x? What is in the box? A: 2 CORRECT B: 3 C: 16 D: Nothing! E: I do not know 9/4/18 Defining Functions 13
14 Understanding How Functions Work Function Frame: Representation of function call A conceptual model of Python Draw parameters as variables (named boxes) Number of statement in the function body to execute next Starts with 1 function name instruction counter parameters local variables (later in lecture) 9/4/18 Defining Functions 14
15 Text (Section 3.10) vs. Class Textbook This Class to_centigrade 1 to_centigrade x > 50.0 x 50.0 Definition: def to_centigrade(x): return 5*(x-32)/9.0 Call: to_centigrade(50.0) 9/4/18 Defining Functions 15
16 Example: to_centigrade(50.0) 1. Draw a frame for the call 2. Assign the argument value to the parameter (in frame) 3. Execute the function body Look for variables in the frame If not there, look for global variables with that name 4. Erase the frame for the call Initial call frame (before exec body) to_centigrade 1 x def to_centigrade(x): return 5*(x-32)/9.0 next line to execute 9/4/18 Defining Functions 16
17 Example: to_centigrade(50.0) 1. Draw a frame for the call 2. Assign the argument value to the parameter (in frame) 3. Execute the function body Look for variables in the frame If not there, look for global variables with that name 4. Erase the frame for the call to_centigrade x Executing the return statement 50.0 RETURN def to_centigrade(x): return 5*(x-32)/9.0 Return statement creates a special variable for result 9/4/18 Defining Functions 17
18 Example: to_centigrade(50.0) 1. Draw a frame for the call 2. Assign the argument value to the parameter (in frame) 3. Execute the function body Look for variables in the frame If not there, look for global variables with that name 4. Erase the frame for the call to_centigrade x Executing the return statement 50.0 RETURN def to_centigrade(x): return 5*(x-32)/9.0 The return terminates; no next line to execute 9/4/18 Defining Functions 18
19 Example: to_centigrade(50.0) 1. Draw a frame for the call 2. Assign the argument value to the parameter (in frame) 3. Execute the function body Look for variables in the frame If not there, look for global variables with that name 4. Erase the frame for the call ERASE WHOLE FRAME 1 def to_centigrade(x): return 5*(x-32)/9.0 But don t actually erase on an exam 9/4/18 Defining Functions 19
20 Call Frames vs. Global Variables The specification is a lie: 1 2 def swap(a,b): """Swap global a & b""" tmp = a a = b Global Variables a 1 b 2 Call Frame 3 b = tmp swap 1 >>> a = 1 >>> b = 2 >>> swap(a,b) a 1 b 2 9/4/18 Defining Functions 20
21 Call Frames vs. Global Variables The specification is a lie: def swap(a,b): """Swap global a & b""" 1 tmp = a 2 a = b 3 b = tmp >>> a = 1 >>> b = 2 >>> swap(a,b) Global Variables a 1 b 2 Call Frame swap 2 a 1 b 2 tmp 1 9/4/18 Defining Functions 21
22 Call Frames vs. Global Variables The specification is a lie: def swap(a,b): """Swap global a & b""" 1 tmp = a 2 a = b 3 b = tmp >>> a = 1 >>> b = 2 >>> swap(a,b) Global Variables a 1 b 2 Call Frame swap 3 x a 1 2 b 2 tmp 1 9/4/18 Defining Functions 22
23 Call Frames vs. Global Variables The specification is a lie: def swap(a,b): """Swap global a & b""" 1 tmp = a 2 a = b 3 b = tmp >>> a = 1 >>> b = 2 >>> swap(a,b) Global Variables a 1 b 2 Call Frame swap x a 1 2 b 2 1 tmp 1 x 9/4/18 Defining Functions 23
24 Call Frames vs. Global Variables The specification is a lie: def swap(a,b): """Swap global a & b""" 1 tmp = a 2 a = b 3 b = tmp Global Variables a 1 b 2 Call Frame >>> a = 1 >>> b = 2 >>> swap(a,b) ERASE THE FRAME 9/4/18 Defining Functions 24
25 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) Function Call What does the frame look like at the start? 9/4/18 Defining Functions 25
26 Which One is Closest to Your Answer? A: B: foo 0 foo 1 C: D: foo 1 x 3 foo 1 x y 9/4/18 Defining Functions 26
27 Which One is Closest to Your Answer? A: B: foo 0 E: foo 1 C: D: foo 1 x 3 \_( )_/ foo 1 x y 9/4/18 Defining Functions 27
28 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) B: Function Call foo 1 9/4/18 Defining Functions 28
29 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) B: Function Call foo 1 What is the next step? 9/4/18 Defining Functions 29
30 Which One is Closest to Your Answer? A: B: foo 2 foo 1 x 3 C: D: foo 2 x 3 foo 2 x 3 y 9/4/18 Defining Functions 30
31 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) C: Function Call foo 2 x 3 9/4/18 Defining Functions 31
32 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) C: Function Call foo 2 x 3 What is the next step? 9/4/18 Defining Functions 32
33 Which One is Closest to Your Answer? A: B: foo 3 x 3 y 4 C: D: foo x 3 y 4 RETURN 16 foo x 3 y 4 RETURN ERASE THE FRAME 3 9/4/18 Defining Functions 33
34 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) A: Function Call foo 3 x 3 y 4 9/4/18 Defining Functions 34
35 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) A: Function Call foo 3 x 3 y 4 What is the next step? 9/4/18 Defining Functions 35
36 Which One is Closest to Your Answer? A: B: foo 3 foo RETURN 16 x 3 y 4 RETURN 16 3 C: D: foo x 3 y 4 RETURN 16 ERASE THE FRAME 9/4/18 Defining Functions 36
37 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) C: foo Function Call x 3 y 4 RETURN 16 9/4/18 Defining Functions 37
38 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) C: foo Function Call x 3 y 4 RETURN 16 What is the next step? 9/4/18 Defining Functions 38
39 Which One is Closest to Your Answer? A: B: foo ERASE THE FRAME RETURN 16 C: D: foo x 16 ERASE THE FRAME x 16 9/4/18 Defining Functions 39
40 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) D: Function Call x 16 ERASE THE FRAME 9/4/18 Defining Functions 40
41 Exercise Time Function Definition def foo(a,b): """Return something Param x: a number Param y: a number""" x = a y = b return x*y+y >>> x = foo(3,4) D: Function Call x Variable in global space 16 ERASE THE FRAME 9/4/18 Defining Functions 41
42 Visualizing Frames: The Python Tutor 9/4/18 Defining Functions 42
43 Visualizing Frames: The Python Tutor Global Space Call Frame 9/4/18 Defining Functions 43
44 Visualizing Frames: The Python Tutor Global Space Variables from second lecture go in here Call Frame 9/4/18 Defining Functions 44
45 Visualizing Frames: The Python Tutor Missing line numbers! 9/4/18 Defining Functions 45
46 Visualizing Frames: The Python Tutor Line number marked here (sort-of) Missing line numbers! 9/4/18 Defining Functions 46
47 Next Time: Text Processing 9/4/18 Defining Functions 47
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 informationLecture 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationCS 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 informationClass Note #02. [Overall Information] [During the Lecture]
Class Note #02 Date: 01/11/2006 [Overall Information] In this class, after a few additional announcements, we study the worst-case running time of Insertion Sort. The asymptotic notation (also called,
More informationAnnouncements for this Lecture
Lecture 6 Objects Announcements for this Lecture Last Call Quiz: About the Course Take it by tomorrow Also remember survey Assignment 1 Assignment 1 is live Posted on web page Due Thur, Sep. 18 th Due
More informationEXPRESSIONS, STATEMENTS, AND FUNCTIONS 1
EXPRESSIONS, STATEMENTS, AND FUNCTIONS 1 COMPUTER SCIENCE 61A September 4, 2013 0.1 Warmup What Would Python Do? >>> x = 6 >>> def square(x):... return x * x >>> square(x) >>> max(pow(2, 3), square(-5))
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 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 informationCOMP 250. Lecture 7. Sorting a List: bubble sort selection sort insertion sort. Sept. 22, 2017
COMP 250 Lecture 7 Sorting a List: bubble sort selection sort insertion sort Sept. 22, 20 1 Sorting BEFORE AFTER 2 2 2 Example: sorting exams by last name Sorting Algorithms Bubble sort Selection sort
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 informationCS 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 informationCS 1110 Final, December 17th, Question Points Score Total: 100
CS 1110 Final, December 17th, 2014 This 150-minute exam has 8 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 informationMore on Arrays CS 16: Solving Problems with Computers I Lecture #13
More on Arrays CS 16: Solving Problems with Computers I Lecture #13 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #12 due today No homework assigned today!! Lab #7 is due on Monday,
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 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 informationProblem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur
Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 15 Branching : IF ELSE Statement We are looking
More informationPointers, Arrays and Parameters
Pointers, Arrays and Parameters This exercise is different from our usual exercises. You don t have so much a problem to solve by creating a program but rather some things to understand about the programming
More informationLast Name: First: Netid: Section. CS 1110 Final, December 17th, 2014
CS 0 Final, December 7th, 204 SOLUTION This 50-minute exam has 8 questions worth a total of 00 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need
More informationCS 1110 Final, December 8th, Question Points Score Total: 100
CS 1110 Final, December 8th, 2016 This 150-minute exam has 8 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 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 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 informationCSE 11 Style Guidelines
CSE 11 Style Guidelines These style guidelines are based off of Google s Java Style Guide and Oracle s Javadoc Guide. Overview: Your style will be graded on the following items: File Headers Class Headers
More informationIntroduction to Python
Introduction to Python EECS 4415 Big Data Systems Tilemachos Pechlivanoglou tipech@eecs.yorku.ca 2 Background Why Python? "Scripting language" Very easy to learn Interactive front-end for C/C++ code Object-oriented
More informationCS 1110 Final, December 8th, Question Points Score Total: 100
CS 1110 Final, December 8th, 2016 This 150-minute exam has 8 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 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 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 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 informationPreviously. Iteration. Date and time structures. Modularisation.
Lecture 7 Previously Iteration. Date and time structures. Modularisation. Today Pseudo code. File handling. Pseudo code Pseudocode is an informal high-level description of the operating principle of 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 informationYou must pass the final exam to pass the course.
Computer Science Technology Department Houston Community College System Department Website: http://csci.hccs.cc.tx.us CRN: 46876 978-1-4239-0146-4 1-4239-0146-0 Semester: Fall 2010 Campus and Room: Stafford
More informationQUIZ Lesson 4. Exercise 4: Write an if statement that assigns the value of x to the variable y if x is in between 1 and 20, otherwise y is unchanged.
QUIZ Lesson 4 Exercise 4: Write an if statement that assigns the value of x to the variable y if x is in between 1 and 20, otherwise y is unchanged. QUIZ Lesson 4 Exercise 4: Write an if statement that
More informationCS 483. Jana Kosecka CS Dept Eng. Building
CS 483 Jana Kosecka CS Dept. 4444 Eng. Building kosecka@gmu.edu Course Info Course webpage: from the syllabus on http://cs.gmu.edu/courses/ Information you will find course syllabus, time table office
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 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 informationCPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O)
CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O) Overview (5) Topics Output: printf Input: scanf Basic format codes More on initializing variables 2000
More informationLecture 02, Fall 2018 Friday September 7
Anatomy of a class Oliver W. Layton CS231: Data Structures and Algorithms Lecture 02, Fall 2018 Friday September 7 Follow-up Python is also cross-platform. What s the advantage of Java? It s true: Python
More informationLast 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 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 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 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 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 informationCS108 Lecture 16: User Defined Classes. Overview/Questions
CS108 Lecture 16: User Defined Classes Aaron Stevens 23 February 2009 1 Overview/Questions Review: the function of functions Thinking about program structure Review: objects and classes How do we design
More informationCS 3030 Scripting Languages Syllabus
General Information CS 3030 Scripting Languages Semester: Fall 2017 Textbook: Location: Instructor Info: None. We will use freely available resources from the Internet. Online Ted Cowan tedcowan@weber.edu
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 08 Lists Constants Last Class We Covered More on while loops Sentinel loops Boolean flags 2 Any Questions from Last Time? 3 Today s Objectives To learn about
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 informationShort Answer Questions (40 points)
CS 1112 Fall 2017 Test 2 Page 1 of 6 Short Answer Questions (40 points) 1. TRUE FALSE You have very legibly printed your name and email id below. Name = EMAILD = 2. TRUE FALSE On my honor, I pledge that
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 information15-110: Principles of Computing, Spring Problem Set 2 (PS2) Due: Friday, February 2 by 2:30PM on Gradescope
15-110: Principles of Computing, Spring 2018 Problem Set 2 (PS2) Due: Friday, February 2 by 2:30PM on Gradescope HANDIN INSTRUCTIONS Download a copy of this PDF file. You have two ways to fill in your
More informationCMSC 201 Fall 2018 Lab 04 While Loops
CMSC 201 Fall 2018 Lab 04 While Loops Assignment: Lab 04 While Loops Due Date: During discussion, September 24 th through September 27 th Value: 10 points (8 points during lab, 2 points for Pre Lab quiz)
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 informationApril 2 to April 4, 2018
MORE SCHEME COMPUTER SCIENCE MENTORS 61A April 2 to April 4, 2018 1 Scheme 1. What will Scheme output? Draw box-and-pointer diagrams to help determine this. (a) (cons (cons 1 nil) (cons 2 (cons (cons 3
More informationWELCOME! (download slides and.py files and follow along!) LECTURE 1
WELCOME! (download slides and.py files and follow along!) 6.0001 LECTURE 1 6.0001 LECTURE 1 1 TODAY course info what is computation python basics mathematical operations python variables and types NOTE:
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 informationProgramming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11
Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11 Ziad Matni Dept. of Computer Science, UCSB Thursday, 5/17 in this classroom Starts at 2:00 PM **SHARP** Please
More informationInformation Science 1
Topics covered Information Science 1 Fundamental Programming Constructs (1) Week 11 Terms and concepts from Week 10 Flow of control and conditional statements Selection structures if statement switch statement
More informationIntroduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1
Review Midterm Exam 1 Review Midterm Exam 1 Exam on Monday, October 7 Data Types and Variables = Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings Data Types and Variables
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationOnly to be used for arranged hours. Order of Operations
Math 84 Activity # 1 Your name: Order of Operations Goals: 1) Evaluate Real numbers with Exponents. ) Use the Order of Operations to Evaluate Expressions. ) Review Exponents and Powers of Ten Integer exponents
More informationLab 4 Fruitful Functions
Lab 4 Fruitful Functions September 19, 2018 1 ME 30 Lab 4 - Functions and Style Description and Summary: >A function in programming is a block of code that performs some task. Functions are a way to organize
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 informationInformation Science 1
Information Science 1 Fundamental Programming Constructs (1) Week 11 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 10 l Flow of control
More informationCS 1110 Final, December 16th, 2013
CS 1110 Final, December 16th, 2013 This 150-minute exam has 8 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 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 informationHomework notes. Homework 2 grades posted on canvas. Homework 3 due tomorrow. Homework 4 posted on canvas. Due Tuesday, Oct. 3
References Homework notes Homework 2 grades posted on canvas Homework 3 due tomorrow Homework 4 posted on canvas Due Tuesday, Oct. 3 Style notes Comment your code! A short line of comments per logical
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 informationLecture 8 Tao Wang 1
Lecture 8 Tao Wang 1 Objectives In this chapter, you will learn about: Sorting 3 numbers review Function overview Function and parameter declarations Function with empty parameter lists Default arguments
More informationVSCode: Open Project -> View Terminal -> npm run pull -> npm start. Lecture 16
VSCode: Open Project -> View Terminal -> npm run pull -> npm start for Loops Lecture 16 Don t Stop Believin I would feel excited and hype because this song is a classic 101 student Announcements Quiz 2
More informationEXPRESSIONS, STATEMENTS, AND FUNCTIONS 1
EXPRESSIONS, STATEMENTS, AND FUNCTIONS 1 COMPUTER SCIENCE 61A June 24, 2014 0.1 Warmup What Would Python Do? >>> x = 6 >>> def square(x):... return x * x >>> square(x) >>> max(pow(2, 3), square(-5)) -
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 informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationCSC148 Recipe for Designing Classes
Part 1: Define the API for the class CSC148 Recipe for Designing Classes Download the sample code here: https://www.teach.cs.toronto.edu/~csc148h/fall/lectures/object-oriented-programming/common/course.
More informationQuiz 1: Functions and Procedures
Quiz 1: Functions and Procedures Outline Basics Control Flow While Loops Expressions and Statements Functions Primitive Data Types 3 simple data types: number, string, boolean Numbers store numerical data
More informationAnnouncements for the Class
Lecture 2 Classes Announcements for the Class Readings Section 1.4, 1.5 in text Section 3.1 in text Optional: PLive CD that comes with text References in text Assignment Assignment 1 due next week Due
More informationAdvanced Object Oriented Programming EECS2030Z
Advanced Object Oriented Programming EECS2030Z 1 Academic Support Programs: Bethune having trouble with your FSC and LSE courses? consider using the Academic Support Programs at Bethune College PASS free,
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 informationUniversity of Texas at Arlington, TX, USA
Dept. of Computer Science and Engineering University of Texas at Arlington, TX, USA The set of program statements over which a variable exists (i.e. can be referred to) It is about understanding, for any
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 informationIntro to Python Programming
Intro to Python Programming If you re using chromebooks at your school, you can use an online editor called Trinket to code in Python, and you ll have an online portfolio of your projects which you can
More informationNot-So-Mini-Lecture 6. Modules & Scripts
Not-So-Mini-Lecture 6 Modules & Scripts Interactive Shell vs. Modules Launch in command line Type each line separately Python executes as you type Write in a code editor We use Atom Editor But anything
More informationAssignment 7: Due Wednesday May 11 at 6pm UPDATES on Monday May 9
CS1110 Spring 2016 Assignment 7: Due Wednesday May 11 at 6pm UPDATES on Monday May 9 You must work either on your own or with one partner. If you work with a partner, you and your partner must first register
More informationENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python
ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python ENGG1811 UNSW, CRICOS Provider No: 00098G W4 Computers have changed engineering http://www.noendexport.com/en/contents/48/410.html
More informationPREPARING 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 informationMORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.
MORE SCHEME COMPUTER SCIENCE MENTORS 61A October 30 to November 3, 2017 1 What Would Scheme Print? Solutions begin on the following page. 1. What will Scheme output? Draw box-and-pointer diagrams to help
More informationLecture 1: Introduction to Python
Hendrik Weimer Institute for Theoretical Physics, Leibniz University Hannover Quantum Physics with Python, 04 April 2016 Goals of this course Learn to use the Python language for physics problems Master
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 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