15-110 PS2 Sample Solutions - Spring 2018 1. (a) 41 - 30 / 3 + 2 41 - 10.0 + 2 31.0 + 2 33.0 (33 also accepted) (b) 3 ** 2 ** 3 3 ** 8 6561 (c) 23456 % 1000 + 23456 % 1000 456 + 23456 % 1000 456 + 456 912 2. (a) Type error - can't add a boolean to a string (b) Value error or domain error - can't take square root of a negative number (c) Syntax error - can't use def as a variable name since it is a reserved word (d) ZeroDivision error - modulo uses division and we can't divide by 0 3. (a) The answer is not correct since the units do not match (feet vs. yards). (b) Python reports an error since the function requires 2 arguments and we only supplied one. (c) Python does not report an error since Python can't tell the meaning of the two numbers so it looks valid. (d) None (the function prints to the screen but does not return an answer to the instruction that called the function 4. (a) 729 (loop iterates 6 times) = 3**6 (b) 3**n (c) 720 = 6! (d) n! (e) The function always returns 3. The return is part of the loop body. During the first iteration, the return exits the function immediately so the loop never completes. 5. (a) Every image from camera, phone, etc. have embedded time and serial number data so if he registered the device, he can be traced. In the reading (on page 24), a case was described about a fan posting pictures of a Harry Potter release online before it was released officially. (b) The EZPass records the time she entered and exited the freeway as well as the distance traveled. Her average speed can be computed which implied that she had to have been speeding at some point along the way. (see page 37 in the reading)