namespace, scope, compile time activities, runtime activities when do the small integer values get...
TRANSCRIPT
![Page 1: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/1.jpg)
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.
![Page 2: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/2.jpg)
Show what happens at each stepduring compilation
and runtime……and before
![Page 3: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/3.jpg)
RAM
start IDLE
![Page 4: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/4.jpg)
RAM
5
4
3
2
1
start IDLE – small integers and single character strings are loaded into RAM
![Page 5: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/5.jpg)
__builtin__ module is imported
RAM
5
4
3
2
1
namespaces
builtin lenprintroundglobal
![Page 6: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/6.jpg)
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 lenprintroundglobal
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
![Page 7: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/7.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
![Page 8: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/8.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
![Page 9: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/9.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
![Page 10: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/10.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
![Page 11: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/11.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 12: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/12.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 13: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/13.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 14: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/14.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
screen
THERE WILL BENO OUPUT UNTILRUN TIME
NO INPUT
''' returns user's coffee order quantity '''
![Page 15: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/15.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
NO INPUT
''' returns user's coffee order quantity '''
![Page 16: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/16.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
NO INPUT
''' returns user's coffee order quantity '''
![Page 17: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/17.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 18: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/18.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 19: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/19.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 20: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/20.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 21: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/21.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 22: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/22.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
''' returns user's coffee order quantity '''
![Page 23: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/23.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity '''
![Page 24: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/24.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity '''
![Page 25: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/25.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity '''
![Page 26: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/26.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''
![Page 27: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/27.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''
![Page 28: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/28.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''
![Page 29: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/29.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''
![Page 30: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/30.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''
![Page 31: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/31.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''
![Page 32: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/32.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''
![Page 33: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/33.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 34: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/34.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 35: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/35.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 36: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/36.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 37: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/37.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 38: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/38.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 39: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/39.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 40: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/40.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 41: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/41.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 42: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/42.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 43: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/43.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 44: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/44.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 45: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/45.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 46: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/46.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 47: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/47.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 48: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/48.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
cups
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 49: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/49.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 50: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/50.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 51: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/51.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
THERE WILL BENO OUPUT UNTILRUN TIME
cups
cupsowed
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 52: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/52.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
screen
cups
cupsowed
cupsowed
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 53: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/53.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 54: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/54.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 55: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/55.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 56: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/56.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 57: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/57.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 58: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/58.jpg)
…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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 59: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/59.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 60: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/60.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 61: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/61.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 62: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/62.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 63: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/63.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 64: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/64.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 65: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/65.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 66: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/66.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 67: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/67.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 68: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/68.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 69: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/69.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 70: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/70.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 71: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/71.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 72: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/72.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 73: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/73.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 74: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/74.jpg)
…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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 75: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/75.jpg)
…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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 76: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/76.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 77: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/77.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 78: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/78.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 79: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/79.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 80: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/80.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 81: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/81.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 82: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/82.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 83: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/83.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 84: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/84.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 85: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/85.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 86: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/86.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 87: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/87.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 88: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/88.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 89: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/89.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 90: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/90.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 91: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/91.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 92: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/92.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 93: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/93.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 94: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/94.jpg)
…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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 95: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/95.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 96: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/96.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 97: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/97.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 98: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/98.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 99: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/99.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 100: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/100.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2You owe $2for your 2 cup(s)
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 101: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/101.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2You owe $2for your 2 cup(s)
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''
![Page 102: 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](https://reader031.vdocuments.net/reader031/viewer/2022013101/56649f305503460f94c4b70b/html5/thumbnails/102.jpg)
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 lenprintroundglobal
PRICE_PER_CUP
getNumCoffeeCups local
calcOwed local
showBill local
main local
RAM
5
4
3
2
1
the help system
cups
cups
cupsowed
cupsowed
screen
How many cups?2You owe $2for your 2 cup(s)
''' returns user's coffee order quantity ''' ''' returns calculated amount owed '''''' presents bill nicely '''