CSE 190p University of Washington Michael Ernst

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Lists Ruth Anderson CSE 140 University of Washington 1.
Memory Management & Method Calls in Java Program Execution © Allan C. Milne v
Lecture 3: Topics If-then-else Operator precedence While loops Static methods Recursion.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there.
Lesson 6 Functions Also called Methods CS 1 Lesson 6 -- John Cole1.
Functions and abstraction Michael Ernst UW CSE 190p Summer 2012.
Introduction to Python and programming Michael Ernst UW CSE 190p Summer 2012.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
The Python interpreter CSE 140 University of Washington Michael Ernst.
Local Variables A local variable is a variable that is declared within a method declaration. Local variables are accessible only from the method in which.
More with Methods (parameters, reference vs. value, array processing) Corresponds with Chapters 5 and 6.
Python – Part 3 Functions 1. Function Calls Function – A named sequence of statements that performs a computation – Name – Sequence of statements “call”
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Class Example - Rationals Rational numbers are represented by the ratio of two integers, a numerator and a denominator, e.g., 2/3. This is opposed to irrational.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
ECE122 Feb. 22, Any question on Vehicle sample code?
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 6 Defining Functions.
Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment.
Functions and abstraction Michael Ernst UW CSE 140 Winter 2013.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Lecture 17 Parameters, Scope, Return values.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Python – Part 3 Functions 1. Getting help Start the Python interpreter and type help() to start the online help utility. Or you can type help(print) to.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
Decisions in Python Boolean functions. A Boolean function This is a function which returns a bool result (True or False). The function can certainly work.
Collections Michael Ernst CSE 190p University of Washington.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
The Python interpreter CSE 160 University of Washington Ruth Anderson 1.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Function and Function call Functions name programs Functions can be defined: def myFunction( ): function body (indented) Functions can be called: myFunction(
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Expressions Methods if else Statements Loops Potpourri.
Methods main concepts – method call – object 's methods – actual parameters – method declaration – formal parameters – return value other concepts – method.
Lists Michael Ernst CSE 140 University of Washington.
Chapter 6 Functions. 6-2 Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5.
Lists Ruth Anderson University of Washington CSE 160 Winter
6. FUNCTIONS Rocky K. C. Chang October 4, 2015 (Adapted from John Zelle’s slides)
1 This week Basics of functions Stack frames Stack vs. Heap (brief intro) Calling conventions Storage classes vs. scope Library functions Overloading.
Functions with Arguments and Return Values, Oh My! CS303E: Elements of Computers and Programming.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Environments and the Contour Model
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
The Python interpreter
Functions and abstraction
Ruth Anderson University of Washington CSE 160 Spring 2015
Chapter 5 Functions DDC 2133 Programming II.
Functions, variables, operators, loops Modularity
Functions and abstraction
Call Stacks, Arguments and Returns
Stack Memory 2 (also called Call Stack)
The Python interpreter
Ruth Anderson University of Washington CSE 160 Winter 2017
Passing Parameters by value
CS2011 Introduction to Programming I Methods (I)
5. Functions Rocky K. C. Chang 30 October 2018
G. Pullaiah College of Engineering and Technology
Bindings, Scope, and Extent
The Python interpreter
The Python interpreter
Functions, Part 2 of 42 Topics Functions That Return a Value
Corresponds with Chapter 5
Problem to solve Given four numbers, days, hours, minutes, and seconds, compute the total number of seconds that is equivalent to them. For example, 0.
The Python interpreter
Lecture 2 - Names & Functions
Presentation transcript:

CSE 190p University of Washington Michael Ernst Types CSE 190p University of Washington Michael Ernst

What types do you know about? int float string boolean list set dict function none file

A function works for particular types def fahr_to_cent(fahr): """Argument is a number, in degrees Fahrenheit. Returns a number, the corresponding degrees Centigrade. """ return (fahr - 32) * 5.0 / 9 fahr_to_cent(212) # When and where does the error occur? fahr_to_cent("32” + “F")

Review: how to evaluate a function call Evaluate the function and its arguments to values If the function value is not a function, execution terminates with an error Create a new stack frame A frame has bindings from variables to values Looking up a variable starts here Proceeds to the next older frame if no match here The oldest frame is the “global” frame All the frames together are called the “environment” Assignments happen here Assign the actual argument values to the formal parameter variables Evaluate the body At a return statement, remember the value and exit If at end of the body, return None Remove the stack frame The call evaluates to the returned value

More examples of function calls Use the Python Tutor: http://people.csail.mit.edu/pgbovine/python/tutor.html

The function can be an expression def double(x): return 2*x myfns = [math.sqrt, int, double, math.cos] myfns[1](3.14) myfns[2](3.14) myfns[3](3.14) def myfunc(): return double myfunc()(2.718)