Chapter 5 Exercise Set 5: PCEP Practice¶
Invocation¶
The PCEP uses the term invocation where this text used a different term. Your task is to figure out which term that is, and then use that understanding to fill in the blanks in the following sentences.
By invoking a ________________, you cause it to execute.
Defining a ______________ does not make it run. It runs when it is invoked.
If you want your ___________ to return a value, you have to invoke it.
What is the output of the following program?
expression = -1 ** 4 + 2 * 4 // 5 if expression < 0: print('@') elif expression > 2: print('@@') else: print('@@@')
What is the output of the following program?
def doit(val): for x in range(-1, 2): if 2 * x < 4: val += 1 else: val += 2 return val print(doit(-2))
What is the output of the following program?
def do_something(thing): for r in range(1, 6): for c in range(-1, 3): if r == c: thing += 2 else: continue else: thing -= 1 return thing print(do_something(5))
What is the output of the following program?
def make_it_happen(thing1, thing2): s = '*' while thing1 != thing2 and thing1: thing1 //= 2 s += '*' else: s += '!' return s print(make_it_happen(16, 2))
What is the output of the following program?
def f(x, y, z): return x + 2 * y + 3 * z print(f(0, z=1, y=3))
What is the output of the following program?
def funky(): n = 4 while (n < 64): n *= 2 obj = funky() print(obj)
What is the output of the following program?
""" Nothing here yet! """