CompSci 101 Sec 01, Spring 2025 Exam 1 Problem 1 a cat b ib c penruler d 5 e blueblue f False g spird h ['pencil', 'pen'] i ['go', 'duke', 'win', 'big'] j rd k blue*red*pink m 5.1 n 12.5 Problem 2 [6, 4, 3] [5, 1, 4, ['go']] [5, 8, 5, 8] [2, 3, 12, [7], 10] [2, 3, 12, [7]] Problem 3A (3 pts) result = lst[1][0] + lst[0][1] OR result = lst[-2][-3] + lst[-3][-3] OR ANY COMBINATION OF THESE SUCH AS: result = lst[1][-3] + lst[0][-3] Problem 3B result = str[4:6] + str[2:4] OR result = str[-5:-3] + str[-7:-5] OR ANY COMBINATION OF THESE SUCH AS: result = str[-5:-3] + str[2:4] Problem 3C result = lst[1][0][4:] OR result = lst[1][0][4:8] OR result = lst[-2][0][-4:] OR ANY COMBINATION OF THESE SUCH AS: result = lst[-2][0][4:] Problem 3D str = "tacogazpachoburritotamale" temp = str.split("o") result = "o-".join(temp) OR result = "o-".join(str.split("o")) 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 stats(opponent, player, points, rebounds): result = opponent + ":" + player + ":" if points >= 10 and rebounds >= 10: return result + "double-double" elif points >=10: return result + "more than 10 points" elif rebounds >= 10: return result + "more than 10 rebounds" else: return result + "practice harder" OR def stats(opponent, player, points, rebounds): result = opponent + ":" + player + ":" if points >= 10 and rebounds >= 10: return result + "double-double" if points >=10: return result + "more than 10 points" if rebounds >= 10: return result + "more than 10 rebounds" return result + "practice harder" OR def stats(opponent, player, points, rebounds): result = "" if points >= 10 and rebounds >= 10: result = "double-double" elif points >=10: result = "more than 10 points" elif rebounds >= 10: result = "more than 10 rebounds" else: result = "practice harder" return opponent + ":" + player + ":" + result OR def stats(opponent, player, points, rebounds): result = "" if points >= 10 and rebounds >= 10: result = "double-double" elif points >=10: result = "more than 10 points" elif rebounds >= 10: result = "more than 10 rebounds" else: result = "practice harder" items = [opponent, player, result] return ":".join(items) 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 longer(wordlist, limit): count = 0 for word in wordlist: if len(word) > limit: count = count + 1 return count OR def longer(wordlist, limit): count = 0 for word in wordlist: length = len(word) if length > limit: count += 1 return count