CompSci 101 Sec 02, Spring 2025 Exam 1 Problem 1 a dog b pi c pencilpen d 5 e redred f False g spidird h ['book', 'pencil'] i ['go', 'duke', 'win', 'big'] j bi k blue-red-pink m 6.1 n 11.5 Problem 2 [5, 8, 7] [7, 1, 4, ['row']] [9, 4, 9, 4] [5, 3, 12, [8], 9] [5, 3, 12, [8]] Problem 3A result = lst[2][2] + lst[0][3] OR result = lst[-1][-3] + lst[-3][-1] OR ANY COMBINATION OF THESE SUCH AS: result = lst[2][-3] + lst[0][-1] Problem 3B result = str[6:8] + str[4:6] OR result = str[-3:-1] + str[-5:-3] OR ANY COMBINATION OF THESE SUCH AS: result = str[6:8] + str[-5:-3] Problem 3C result = lst[1][1][:3] OR result = lst[1][1][0:3] OR result = lst[-2][-1][-6:-3] OR ANY COMBINATION OF THESE SUCH AS: result = lst[-2][-1][:3] Problem 3D str = "melonraisinlemonapple" temp = str.split("n") result = "n*".join(temp) OR result = "n*".join(str.split("n")) Problem 4 def chairs(total, perc1, perc2): num1 = int(perc1 * total) num2 = int(perc2 * total) return total - num1 - num2 OR def chairs(total, perc1, perc2): num1 = int(perc1 * total) num2 = int(perc2 * total) answer = total - num1 - num2 return answer OR def chairs(total, perc1, perc2): num1 = int(perc1 * total) num2 = int(perc2 * total) sum = num1 + num2 return total - sum OR def chairs(total, perc1, perc2): num1 = math.floor(perc1 * total) num2 = math.floor(perc2 * total) return total - num1 - num2 OR def chairs(total, perc1, perc2): num1 = math.trunc(perc1 * total) num2 = math.trunc(perc2 * total) return total - num1 - num2 Problem 5 def pickFruit(farm, limit, apples, pears): result = farm + ":limit is " + str(limit)+":" if apples >= limit and pears >= limit: return result + "too many of both" elif apples >= limit: return result + "too many apples" elif pears >= limit: return result + "too many pears" else: return result + "picked the right amount" OR def pickFruit(farm, limit, apples, pears): result = farm + ":limit is " + str(limit)+":" if apples >= limit and pears >= limit: result = result + "too many of both" elif apples >= limit: result = result + "too many apples" elif pears >= limit: result = result + "too many pears" else: result = result + "picked the right amount" return result OR def pickFruit(farm, limit, apples, pears): result = "" if apples >= limit and pears >= limit: result = "too many of both" elif apples >= limit: result = "too many apples" elif pears >= limit: result = "too many pears" else: result = "picked the right amount" result = farm + ":limit is " + str(limit)+":" + result return result OR def pickFruit(farm, limit, apples, pears): result = "" if apples >= limit and pears >= limit: result = "too many of both" elif apples >= limit: result = "too many apples" elif pears >= limit: result = "too many pears" else: result = "picked the right amount" items = [farm, "limit is " + str(limit), result] return ":".join(items) OR def pickFruit(farm, limit, apples, pears): result = farm + ":limit is " + str(limit)+":" if apples >= limit and pears >= limit: return result + "too many of both" if apples >= limit: return result + "too many apples" if pears >= limit: return result + "too many pears" return result + "picked the right amount" Problem 6 def compose(word1, word2, word3, word4): num = random.randint(1,2) ans = "" if num == 1: ans = word1 else: ans = word2 num = random.randint(1, 2) if num == 1: ans = ans + " " + word3 else: ans = ans + " " + word4 return ans OR def compose(word1, word2, word3, word4): num = random.randint(1,4) ans = "" if num == 1: ans = word1 + word3 elif num == 2: ans = word1 + word4 elif num == 3: ans = word2 + word3 else: ans = word2 + word4 return ans OR def compose(word1, word2, word3, word4): num = random.randint(1,4) ans = "" if num == 1: ans = word1 + word3 if num == 2: ans = word1 + word4 if num == 3: ans = word2 + word3 if num == 4: ans = word2 + word4 return ans OR def pick(word1, word2, word3, word4): return random.choice([word1+word3, word1+word4, word2+word3, word2+word4]) Problem 7 PART A: hugesmall OR tinytiny OR Any two words from the list on line 9 stuck together. PART B: onefour OR sixone OR fourfour OR any combination of two words from: ["one", "four", "six"] PART C: list PART D: The code randomly pick a word from wordlist, then randomly picks a second word from wordlist, and then concatenates them together PART E: Line 3 or line 5 (must list both of them) OR Could be interpreted as Line 2 or line 4 (must list both of them) PART F: Trying to index into a position in the list that does not exist. It is trying to index into the position just past the end of the list. PART G: line 3 should be: newPhrase = wordlist[index-1] and line 5 should be: newPhrase = newPhrase + wordlist[index-1] OR Another way to fix it: line 2 and line 4 should both be: index = random.randint(0, len(wordlist)-1) Problem 8 def numsLarger(lst, largest): count = 0 for num in lst: if num > largest: count = count + 1 return count OR def numsLarger(lst, largest): count = 0 for num in lst: if num > largest: count += 1 return count