Question 10
What is the output of the following code? [3 marks]
Solution
For fn(1):
t = 1. We also definex = 1**2 = 1andy = 1**3 = 1.x > 1 and y > 1:False and False = False\(\Rightarrow\) skip if blockx > 1 or y > 1:False or False = False\(\Rightarrow\) skip elif blocky < 1:False\(\Rightarrow\) skip elif block- return
x * y = 1 * 1 = 1
For fn(0):
t = 0. We also definex = 0**2 = 0andy = 0**3 = 0.x > 1 and y > 1:False and False = False\(\Rightarrow\) skip if blockx > 1 or y > 1:False or False = False\(\Rightarrow\) skip elif blocky < 1:True\(\Rightarrow\) enter elif block- return
False
For fn(2):
t = 2. We also definex = 2**2 = 4andy = 2**3 = 8.x > 1 and y > 1:True and True = True\(\Rightarrow\) enter if block- return
True
Hence, the print statement below outputs 1, False and True, in this order separated by spaces.