CompSci 101 Sec01, Fall 2025 Exam 1 Problem 1 a lion <- starts with lion b uf c sailenginesailengine d 5 e hota f True g beful h ['sail', 'hot', 'windy'] i ['run', 'five', 'miles'] j tif k cool#hot#windy m 5.1 n 11.0 o 3 Problem 2 PARTS A-C [7, 4, 1, 4] [8, 2, [5, 4]] [8, 9, 8, 9] PART D [7, 3, 9, 5] [7, 3, 9, 5] PART E [7, 2, [8], 5, 4] [7, 2, [8], 5] Problem 3 PART A result = lst[0][2] + lst[2][1] OR result = lst[-3][-4] + lst[-1][-2] OR ANY COMBINATION OF THESE SUCH AS: result = lst[0][-4] + lst[2][-2] PART B result = word[6:9] + word[3:5] OR result = word[-4:-1] + word[-7:-5] OR result = word[-4:-1] + word[3:5] OR ANY COMBINATION OF THESE SUCH AS: result = word[6:-1] + word[3:-5] PART C result = lst[0][1][3:] OR result = lst[-3][-1][-3:] OR ANY COMBINATION OF THESE SUCH AS: result = lst[-3][1][-3:] PART D word = "boattraytrailtrawl" temp = word.split("tra") result = "bo".join(temp) OR result = "bo".join(word.split("tra")) Problem 4 def purchaseBooks(cost, taxPercent, discount): result = cost - (cost * discount/100.0) result = result + (result * taxPercent/100.00) return result OR def purchaseBooks(cost, taxPercent, discount): result = cost - (cost * (discount * 0.01)) result = result + (result * (taxPercent * 0.01)) return result OR def purchaseBooks(cost, taxPercent, discount): result = cost * (1 - discount/100.0) result = result *(1 + taxPercent/100.00) return result OR def purchaseBooks2(cost, taxPercent, discount): num1 = discount/100 # works whether 100 is int of float num2 = taxPercent/100 # works whether 100 is int of float result = cost - num1*cost answer = result + result*num2 return answer Problem 5 def restockPopsicles(amount1, amount2, low): answer = "" if amount1 < low: pop1 = low - amount1 + 10 answer = str(pop1) + " D; " else: answer = "0 D; " if amount2 < low: pop2 = low - amount2 + 5 answer += str(pop2) + " N" else: answer += "0 N" return answer OR def restockPopsicles(amount1, amount2, low): answer = "" if amount1 < low: pop1 = low - amount1 + 10 else: pop1 = 0 if amount2 < low: pop2 = low - amount2 + 5 else: pop2 = 0 answer = str(pop1) + " D; " + str(pop2) + " N" return answer Problem 6 def compose(wordA, wordB, wordC, numA, numB): num = random.randint(1,3) ans = "" if num == 1: ans = wordA elif num == 2: ans = wordB else: ans = wordC num = random.randint(numA, numB) return ans + str(num) OR def compose(wordA, wordB, wordC, numA, numB): word = random.choice([wordA, wordB, wordC]) num = random.randint(numA, numB) return word + str(num) Problem 7 PART A: 4 5 8 PART B: 4 5 9 PART C: 7 5 9 PART D: 4 8 7 PART E: The code does not check all the cases. For example, if num1 is the largest, it doesn't check how num2 and num3 compare. OR Three values could be presented six different ways: a b c, a c b, b a c, b c a, c a b, c b a. This function only checks and prints them four ways. PART F: Semantic PART G: In line 4 we need another if statement to compare num2 vs num3. In line 10 we need another if statement to compare num2 vs num3. OR In both if statements, we need to add another if statement to compare num2 vs num 3. YOU WERE NOT SUPPOSED TO WRITE THE CODE BUT HERE IS WHAT IT WOULD LOOK LIKE: def sortNumsCorrect(num1, num2, num3): if num1 > num2: if num1 > num3: if num2 > num3: print(num3, num2, num1) else: print(num2, num3, num1) else: print(num2, num1, num3) else: if num1 > num3: print(num3, num1, num2) else: if num2 > num3: print(num1, num3, num2) else: print(num1, num2, num3)