Namespace, scope, compile time activities, runtime activities When do the small integer values get stored in RAM? How did the names in the builtin namespace.

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Introduction to Python
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Chapter 8 Arrays and Strings
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Review of C++ Programming Part II Sheng-Fang Huang.
6 Steps of the Programming Process
Python Programming Fundamentals
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
Introduction to Python
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Chapter 8 Arrays and Strings
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 4: Control Structures I (Selection)
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
With Python.  One of the most useful abilities of programming is the ability to manipulate files.  Python’s operations for file management are relatively.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Python Functions.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Variables, Expressions and Statements
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
INLS 560 – F UNCTIONS Instructor: Jason Carter.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
Introduction to Programming
Controlling Program Flow with Decision Structures.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Course A201: Introduction to Programming 09/09/2010.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
Introduction to Programming
User-Written Functions
Java Programming: From Problem Analysis to Program Design, 3e Chapter 7 User-Defined Methods.
What Actions Do We Have Part 1
Introduction to Python
Introduction To Repetition The for loop
Completing the Problem-Solving Process
Programming Fundamental
Chapter 2 Assignment and Interactive Input
ECS10 10/10
Objectives Identify the built-in data types in C++
Variables, Expressions, and IO
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
General Computer Science for Engineers CISC 106 Lecture 03
Presentation transcript:

Namespace, scope, compile time activities, runtime activities When do the small integer values get stored in RAM? How did the names in the builtin namespace get there before compilation started? Assume there are no syntax errors. In the follow code, assume the user types 2 when prompted. Notice that we are using an int value for the price of coffee in this version.

Show what happens at each step during compilation and runtime… …and before

RAM start IDLE

RAM start IDLE – small integers and single character strings are loaded into RAM

__builtin__ module is imported RAM namespaces builtin len print round global

compilation proceeds from top to bottom in source file – line 1. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME

line 1. global constant PRICE_PER_CUP added to global namespace and bound to 1 code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME

line 2. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME

line 2. the function name added to global namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME

line 3. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME

line 3. docstring added to help system code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 4. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 4. RHS looks fine – no searching is done code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 4. no input, no function calls code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system screen THERE WILL BE NO OUPUT UNTIL RUN TIME NO INPUT ''' returns user's coffee order quantity '''

line 4. cups is added to getNumCoffeeCups’ local namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME NO INPUT ''' returns user's coffee order quantity '''

line 4. no assignment is done – assignment is a runtime activity, no arrow appears code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME NO INPUT ''' returns user's coffee order quantity '''

line 5. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 5. looks like a return statement – no searching is done. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 5. no value is returned – this is compile time. returning a value is a run time activity code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

getNumCoffeeCups’ compiled body is placed into RAM, ready to be called – no run code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 6. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 6. the function name is added to global code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME ''' returns user's coffee order quantity '''

line 6. parameter name is added to calcOwed’s local namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity '''

notice that there are two “cups” names in two different namespaces – different scopes code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity '''

getNumCoffeeCups’s creator chose a good name. calcOwed’s creator chose a good name. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity '''

calcOwed’s creator doesn’t even know that any other functions exist code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''

line 7. – docstring added to help system code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''

line 8. looks like an arithmetic expression and a return statement – no searching is done code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''

calcOwed’s compiled body is placed into RAM, ready to be called – no run happens code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''

line 9. code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''

line 9. – function name is added to global namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''

line 9. – parameter names are added to showBill’s local namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''

line 10. – docstring is added to help system code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

lines 11. and 12. – print() looks like a function call – no searching is done code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

lines 11. and 12. – those str()’s look like a function calls no searching is done code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

lines 11. and 12. – str expression compiles – everything is fine code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

showBill’s compiled body is placed into RAM, ready to be called – no execution, no run code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

notice that there are three “cups” names in three different namespaces – different scopes code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

again, no conflict because the three ‘cups’s are in different scopes – different namespaces code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line13. the function name: main is added to the global namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

there is no docstring written under main’s def line – the program level docstring is at the top code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 14. no function call happens – this is compile time, function calls happen at run time code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 14. getNumCoffeeCups() looks like a function call so compiler is happy code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 14. the assignment statement does not happen – it will at run time, not now code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 14. cups is added to the main’s local namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 15. again no function call happens – it looks like a function call - fine code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 15. no search is made to see if cups already exists – that will be done at run time code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 15. the assignment statement is not executed code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed cups ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 15. owed is added to main’s local namespace – stil no name conflicts! code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 16. looks like a function call – no searching happens – no call happens code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

main’s compiled body is placed into RAM, ready to be called – no execution, no run code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen THERE WILL BE NO OUPUT UNTIL RUN TIME cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

compile time has ended – now we enter exectution or run time at the call of main() code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups screen cups cups owed ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

compile time has ended – now we enter exectution or run time at the call of main() code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

run time order is the order of function calls and returns and starts with the call to main() code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the name main is searched for – LEGB and found –NameError does not occur code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

if there is no communication through parameters, execution continues in the body of main code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the RHS of the assignment is evaluated – it’s a function call, so… code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

…the name getNumCoffeeCups is searched for LEG and found in the global namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

since there is no communication via parameters, the first line in getNumCoffeeCups runs code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

raw_input is searched for – LEGB finally found in the builtin namespace – no NameError code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

raw_input is passed the prompt string and it shows it to the user code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the user hits the 2 button, hits the Enter button, the newline is trashed, the str ‘2’ is returned code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the name int is searched for – LEGB and found in the builtins code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the returned ‘2’ is passed to int(_) which returns the int 2 which is now the value of the RHS code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

now that the RHS’s value is fully known, the run time system looks to see if the 2 is in RAM code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the value of the int(raw_input(“..”)) function call expression becomes the returned 2 code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the value of the int(raw_input(“..”)) function call expression becomes the returned 2 code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the LHS, cups, is searched for: L – found in the local namespace of getNumCoffeeCups code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

cups is made to point at where the 2 is in RAM – cups is bound to the RAM containing the 2 code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

notice that there is no confusion about which ‘cups’ is assigned to – it’s scope is local code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? " 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

return cups – cups is again searched for and found in the locals of getNumCoffeeCups code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

return returns to it’s caller a reference to where the 2 is in RAM code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the value of the function call expression becomes the value returned, the run continues there code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

…and all local references back at the call go away – cups stays in the local namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

…and all local references back at the call go away – cups stays in the local namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

getNumCoffeeCup’s local cups is no longer in scope when its lifetime ended after the return code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

main’s local cups is searched for in main’s local and found and the assignment occurs code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

main’s local cups is searched for in main’s local and found and the assignment occurs code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''‘ 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

line 15. – function call on RHS – calcOwed is found in the globals – no NameError code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

cups is searched for and found in main’s locals… code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

setting up the call to calcOwed - its parameter name ‘cups’ searched for and found locally code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

calcOwed’s local parameter name ‘cups’ is assigned main’s local variable ‘cups’ code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

this is pass by asasignment code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

now that the communication via parameters has been set up, the body is executed code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the expression to be returned is evaluated, cups is found in calcOwed’s locals code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

PRICE_PER_CUP is searched for – LEGB, found in the global namespace code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

cups * PRICE_PER_CUP is evaluated and that value is searched for in RAM and found code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the expression becomes that value code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

back at the call, the function call becomes the returned value code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

and all local references in calcOwed go away – they are no longer bound to values in RAM code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

and all local references in calcOwed go away – they are no longer bound to values in RAM code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

execution continues on the line with the call code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

owed is searched for and found in main’s local namespace… code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

…and the assignment is made code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

we’ll speed things up a bit now code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

find showBill in the globals, cups and owed in the main’s locals code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

find showBill’s parameters code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

pass by assignment code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

find print and str in builtins, look up owed’s and cups’ values code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

the string is built, looked for in RAM, not found, stored in RAM somewhere, passed, printed code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 You owe $2 for your 2 cup(s) ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

execution returns to the caller: main(), local references in showBill go away, names stay code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 You owe $2 for your 2 cup(s) ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''

main() call is over, local references in main go away, execution ends – WHEW! code 1. PRICE_PER_CUP = 1 # in US$ 2. def getNumCoffeeCups(): 3. ''' returns user's coffee order quantity ''' 4. cups = int( raw_input( "How many cups? “ ) ) 5. return cups 6. def calcOwed( cups ): 7. ''' returns calculated amount owed ''' 8. return cups * PRICE_PER_CUP 9. def showBill( cups, owed ): 10. ''' presents bill nicely ''' 11. print( "You owe $" + str( owed ) + "\n" + \ 12. "for your " + str( cups ) + " cups(s)" ) 13. def main(): 14. cups = getNumCoffeeCups() 15. owed = calcOwed( cups ) 16. showBill( cups, owed ) 17. main() namespaces builtin len print round global PRICE_PER_CUP getNumCoffeeCups local calcOwed local showBill local main local RAM the help system cups cups owed screen How many cups? 2 You owe $2 for your 2 cup(s) ''' returns user's coffee order quantity ''' ''' returns calculated amount owed ''' ''' presents bill nicely '''