Problem 1 --------- (a) float(str(54/10) + "03") 5.403 (b) (random.randint(0, 10)*10 <= 100) or (random.randint(0, 10) < 5) True (c) int(str(543 % 10) + str(543 // 10)) 354 (d) math.sqrt(16) + 3 7.0 (e) (not not not True) and True False (f) 76 // 10 + 76 / 10 14.6 (g) int(5 + random.random())//2 2 (h) (153 < 153) or (not (175 != 198)) False (i) "The answer is"+ " " + str(0.5) 'The answer is 0.5' (j) str(15.0//3 + 3//2) '6.0' Problem 2 ---------- (a) 5 4 5 6 *** 6 5 6 7 6 9 *** 7 6 *** 8 7 8 9 *** 9 8 9 10 9 12 *** (b) 20 19 16 19 foo1: m -> parameter, n -> local variable, y -> global variable foo2: p -> parameter, y -> global variable Problem 3 --------- (a) error = 0 # tracks the number of errors count = 0 # tracks the total number of words typed by user while True: word = input() count = count + 1 # Increment variable error if the user has made an error # Blank 1 if word != "mongoose" and word != "squirrel" and word != "possum": error = error + 1 if error == 3: break # Output percentage of correct words # Blank 2 print("Percentage of correct words:", 100*(count - error)/count) (b) def cubeRoot(s, e): oldX = s/3 # initial guess # The next value of x # Blank 1 newX = (s/(oldX*oldX) + 2*oldX)/3 while True: # If the new x and the oldx are close # enough, then return an answer # Blank 2 if abs(oldX - newX) <= e: return newX # Update newX and oldX # Blank 3 oldX = newX newX = (s/(oldX*oldX) + 2*oldX)/3 Problem 4 ---------- (a) def isPerfectCube(n): x = int(cubeRoot(n, 0.5)) return (x**3 == n) or ((x+1)**3 == n) (b) def encode(n, k): codedNumber = "" while n > 0: codedNumber = str((n % 10 + k) % 10) + codedNumber n = n // 10