SLIDE 1
x = 15 coord = 3*(x-2.7) x , = , 15 , , coord , = , 3, *, (, - - PowerPoint PPT Presentation
x = 15 coord = 3*(x-2.7) x , = , 15 , , coord , = , 3, *, (, - - PowerPoint PPT Presentation
x = 15 coord = 3*(x-2.7) x , = , 15 , , coord , = , 3, *, (, x , - , 2.7, ) ... = = * x 15 coord 3 = x 15 x 2.7 LOAD_CONST 0 # load the literal (constant) at loc. 0 x = 5 y = 7 z = x + y LOAD_CONST LOAD_NAME
SLIDE 2
SLIDE 3
SLIDE 4
SLIDE 5
x = 15 coord = 3*(x-2.7)
SLIDE 6
= x 15 x, =, 15, , coord, =, 3, *, (, x, -, 2.7, )
coord x 2.7 – = x = 15 ...
*
3
SLIDE 7
SLIDE 8
SLIDE 9
LOAD_CONST 0 # load the literal (constant) at loc. 0
SLIDE 10
x = 5 y = 7 z = x + y
SLIDE 11
LOAD_CONST LOAD_NAME STORE_NAME BINARY_ADD BINARY_SUBTRACT
SLIDE 12
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 13
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 14
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 15
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 16
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 17
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 18
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 19
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 20
x = 5 y = 7 z = x + y LOAD_CONST 0 # 5 STORE_NAME 0 # x LOAD_CONST 1 # 7 STORE_NAME 1 # y LOAD_NAME 0 # x LOAD_NAME 1 # y BINARY_ADD STORE_NAME 2 # z
SLIDE 21
a b c
LOAD_CONST 0 STORE_NAME 0 LOAD_NAME 0 LOAD_CONST 1 BINARY_SUBTRACT STORE_NAME 1 LOAD_NAME 0 LOAD_NAME 1 BINARY_ADD STORE_NAME 2
SLIDE 22
inner
- uter
- uter
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7 print(outer(4)) inner
- uter
SLIDE 23
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7
- uter(4)
Call Stack [ ] ; outer(4)
SLIDE 24
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7
- uter(4)
Call Stack [x=4] ; y = x / 2 [ ] ; outer(4)
SLIDE 25
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7
- uter(4)
Call Stack [x=4, y=2.0] ; return inner(y) + 7 [ ] ; outer(4)
SLIDE 26
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7
- uter(4)
Call Stack [x=4, y=2.0] ; return inner(2.0) + 7 [ ] ; outer(4) [x=2.0] ; y = x + 1
SLIDE 27
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7
- uter(4)
Call Stack [x=4, y=2.0] ; return inner(2.0) + 7 [ ] ; outer(4) [x=2.0, y=3.0] ; return y
SLIDE 28
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7
- uter(4)
Call Stack [x=4, y=2.0] ; return 3.0 + 7 [ ] ; outer(4)
SLIDE 29
def inner(x): y = x + 1 return y def outer(x): y = x / 2 return inner(y) + 7
- uter(4)
Call Stack [ ] ; 10.0
SLIDE 30
SLIDE 31
def payForMeal(cash, cost): cash = cash - cost print("Thanks!") return cash wallet = 20.00 wallet = payForMeal(wallet, 7.25) Call Stack [ ] ; wallet = 20.00 >>>
SLIDE 32
def payForMeal(cash, cost): cash = cash - cost print("Thanks!") return cash wallet = 20.00 wallet = payForMeal(wallet, 7.25) Call Stack [ wallet=20.00 ] ; wallet = payForMeal(wallet, 7.25) >>>
SLIDE 33
def payForMeal(cash, cost): cash = cash - cost print("Thanks!") return cash wallet = 20.00 wallet = payForMeal(wallet, 7.25) Call Stack [ wallet=20.00 ] ; wallet = payForMeal(20.00, 7.25) [ cash=20.00, cost=7.25 ] ; cash = cash-cost >>>
SLIDE 34
>>> def payForMeal(cash, cost): cash = cash - cost print("Thanks!") return cash wallet = 20.00 wallet = payForMeal(wallet, 7.25) Call Stack [ wallet=20.00 ] ; wallet = payForMeal(20.00, 7.25) [ cash=12.75, cost=7.25 ] ; print("Thanks!") Thanks! >>>
SLIDE 35
def payForMeal(cash, cost): cash = cash - cost print("Thanks!") return cash wallet = 20.00 wallet = payForMeal(wallet, 7.25) Call Stack [ wallet=20.00 ] ; wallet = payForMeal(20.00, 7.25) [ cash=12.75, cost=7.25 ] ; return cash Thanks! >>>
SLIDE 36
def payForMeal(cash, cost): cash = cash - cost print("Thanks!") return cash wallet = 20.00 wallet = payForMeal(wallet, 7.25) Call Stack [ wallet=20.00 ] ; wallet = 12.75 Thanks! >>>
SLIDE 37
def payForMeal(cash, cost): cash = cash - cost print("Thanks!") return cash wallet = 20.00 wallet = payForMeal(wallet, 7.25) Call Stack [ wallet=12.75 ] Thanks! >>>
SLIDE 38
SLIDE 39
SLIDE 40
x = @ # @ is not a valid token 4 + 5 = x # the parser stops because it doesn't follow the rules x = 4 # IndentationError: whitespace has meaning print(4 + 5 # Incomplete Error: always close parentheses/quotes
SLIDE 41
SLIDE 42
print(Hello) # NameError: used a missing variable print("2" + 3) # TypeError: illegal operation on types x = 5 / 0 # ZeroDivisionError: can't divide by zero
SLIDE 43
SLIDE 44
print("2 + 2 = ", 5) # no error message, but wrong! def double(x): return x + 2 # adding instead of multiplying
SLIDE 45
SLIDE 46