The red dot indicates the next thing to do in the script s1 1115 s2 1205 x Ts1

# The red dot indicates the next thing to do in the

This preview shows page 42 - 54 out of 67 pages.

The red dot indicates the next thing to do in the script.
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 2 s1 s2 x y numMin ‘11:15’
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 3 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z Function call We open up a “call frame” that shows the “key players”associated with the function
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 3 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return The variable sis the function’s parameter
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 3 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return The variables h, m, and zis the function’s local variables
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 3 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return returnis a special variable. Will house the value to return
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 4 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return Control passes from the red dot to the blue dot
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 5 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return Assign the argument value (housed in s1) to the parameter s. ‘11:15’
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 5 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return Assign the argument value (housed in s1) to the parameter s. ‘11:15’
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 6 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return We step through the function body. Business as usual. ‘11:15’11
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 7 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return ‘11:15’11 15 We step through the function body. Business as usual.
s1 = ‘11:15’s2 = ‘12:05’x = T(s1) y = T(s2) if y>=x: numMin = y-x else: numMin = (y+720)-x print numMin 8 s1 s2 x y numMin ‘11:15’‘12:05’def T(s): h = int(s[:2]) m = int(s[3:]) if h<12: z = 60*h+m else: z = m return z s h m z return We step through the function body. Business as usual.

#### You've reached the end of your free preview.

Want to read all 67 pages?

• Fall '19
• Subroutine, Return statement