# # Question 1 # # int 0 # bool True # int 10 # str 'bc' # str 'z' # str 'a' # str 'COMPSCI 101' # float 0.5 # # Question 2 # # The picture is an widening spiral of square shapes, sort of like this: # _______ # | ____ | # | | __| | # | | | # ----- # # Question 3 # # Part A # index+2 skips the comma and space to get the first name # the slice uses index to get everything up to and NOT including the comma # Part B # .find() returns -1 when the string is not found, so -1+2 = 1 and the # slice gets "ob jones". The value of the slice "bob jones"[:-1] is # everything up to and not including the last character or "bob jone" # # Question 4 # # Part A # D # The first loop runs 19 times, the second runs 20 times. # Part B # C # The else ensures the function returns after the loop's first iteration. # # Question 5 # # Part A def isAbundant (num): total = 0 for n in range(1, num): if num % n == 0: total = total + n return total > num # Part B def abundantCount (start, end): total = 0 for n in range(start, end+1): if isAbundant(n): total += 1 return total # # Question 6 # # Part A # Testcase 1 fails because an & is always added, even for just one name # & Duvall, LLC # Terrible & Great, LLC # Pearson Hardman & Specter, LLC # Part B # # Testcase 1 fails because the name is not included when there is only one # , LLC # Terrible & Great, LLC # Pearson Hardman & Specter, LLC # # Question 7 # # Part A def getAgeList(filename, low, high): file = open(filename) results = [ ] for line in file: data = line.strip().split(",") age = int(data[2]) if low <= age <= high: results += [ data[0] ] return results # Part B def getLongestGestation (filename): file = open(filename) maxGestation = 0 maxAnimal = '' for line in file: data = line.strip().split(",") gestation = int(data[1]) if gestation > maxGestation: maxGestation = gestation maxAnimal = data[0] return [ maxAnimal, maxGestation ]