15-110 PS3 Sample Solutions - Spring 2018 1. (a) CIRCLE(2,2,2) CIRCLE(2,6,2) CIRCLE(4,4,2) CIRCLE(4,4,3) CIRCLE(6,2,2) CIRCLE(6,6,2) (b) SQUARE(0,8,4) SQUARE(1,8,3) SQUARE(1,7,3) SQUARE(4,4,4) SQUARE(4,4,3) SQUARE(5,3,3) 2. (a) x y temp p q 60 105 - 6300 - 105 60 105 6300 60 60 45 60 6300 105 45 15 45 6300 140 15 0 15 6300 420 (b) lcm2(60,105,0) --> lcm2(60,105,105) --> lcm2(60,105,210) --> lcm2(60,105,315) --> lcm2(60,105,420) --> 420 3. (a) def compute_sum(numlist): total = 0 i = 0 while i < len(numlist): total = total + numlist[i] i = i + 1 return total (b) def compute_sum(numlist): total = 0 for item in numlist: total = total + item return total 4. (a) Change line 20 to: return len(primelist) (b) Change line 20 to: return primelist[-1] (or primelist[len(primelist)-1]) (c) The result is [4,8,12,16]. If an element is removed, the subsequent values shift over so there is a new value in this same position to be checked, but the for loop moves on. (d) Change line 20 to: return primelist + numlist