Practice Questions · AP CSP-Feeder · US / ON / BC / AB Styles练习题集 · AP CSP 衔接 · 美 / 安 / 卑 / 阿省风格
Questions mix multiple-choice and short-answer items. For MCQs, circle the letter and show any trace in the work space. For short-answer items, write exact output or state the structure name clearly. Code is pseudocode or Python; trace each step before answering.本部分包含选择题与短答题。选择题请圈出字母,并在答题空白处写出追踪过程。短答题写出精确输出或清晰说明结构名称。代码为伪代码或 Python;作答前逐步追踪。
Given temps = [15, 22, 18, 30, 27], which statement is correct?给定 temps = [15, 22, 18, 30, 27],以下哪个说法正确?
temps[2] has value 22temps[2] 的值为 22temps[2] has value 18temps[2] 的值为 18len(temps) is 4len(temps) 为 45最后一个有效索引为 5What does the following program output?以下程序输出什么?
data = [10, 20, 30, 40, 50]
total = 0
for i in range(0, 3):
total += data[i]
print(total)
1509060100A program builds and modifies a list step by step.一个程序逐步构建并修改列表。
cart = []
cart.append("apples")
cart.append("bread")
cart.insert(1, "milk")
cart.remove("bread")
cart.append("eggs")
cart after all five operations complete.写出全部五次操作完成后 cart 的最终内容。 [2]cart.insert(1, "milk") does to the list. State which element is shifted and in which direction.解释 cart.insert(1, "milk") 对列表的操作。说明哪个元素被移动,向哪个方向移动。 [2]remove("bread") and pop(1) in one sentence.用一句话说明 remove("bread") 和 pop(1) 的区别。 [1]For each scenario below, identify the most appropriate data structure (list, 2D array, dictionary, set, or tuple) and give a one-sentence justification.对于以下每个场景,确定最合适的数据结构(列表、二维数组、字典、集合或元组),并用一句话说明理由。
(latitude, longitude) for a fixed location that should never change.存储固定位置的 GPS 坐标对 (纬度, 经度),该位置不应改变。 [2]A program tracks student grades using a dictionary.一个程序使用字典跟踪学生成绩。
grades = {}
grades["Alice"] = 91
grades["Bob"] = 78
grades["Carol"] = 85
grades["Bob"] = 82
for name, score in grades.items():
if score >= 85:
print(name)
grades["Bob"] after all assignments complete. Explain why.所有赋值完成后,写出 grades["Bob"] 的最终值并解释原因。 [2]"Dave" with score 70 to the dictionary.写一行 Python,将新学生 "Dave"(成绩 70)添加到字典中。 [1]Show every step of your trace. Write pseudocode or Python clearly, with correct indentation. For justify questions, two sentences of reasoning earn full marks. Code in questions is un-translated pseudocode or Python.写出每一步追踪过程。伪代码或 Python 须清晰书写,缩进正确。论证题两句推理即可满分。题目中的代码为语言无关的伪代码或 Python。
Study the two programs below.研究以下两个程序。
Program A (tuple):程序 A(元组):
point = (3, 7)
print(point[0])
# point[0] = 5 # This line is commented out
Program B (set):程序 B(集合):
scores = [85, 90, 85, 74, 90, 65]
unique = set(scores)
print(len(unique))
print(85 in unique)
A program processes a list of test scores to find the maximum and filter out failing scores.一个程序处理一系列测试成绩,找出最高分并过滤掉不及格成绩。
scores = [72, 45, 88, 61, 95, 38, 77]
# Part (a): find maximum
max_val = scores[0]
for i in range(1, len(scores)):
if scores[i] > max_val:
max_val = scores[i]
# Part (b): build passing list
passing = []
for s in scores:
if s >= 60:
passing.append(s)
i | scores[i] | Update max_val?更新 max_val? | max_val |
|---|---|---|---|
| 1 | |||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 |
passing after the second loop completes.写出第二个循环完成后 passing 的最终内容。 [2]1 rather than 0? Justify in two sentences.为什么求最大值的循环从索引 1 而不是 0 开始?用两句话说明理由。 [2]passing and the length of the original scores list.写出 passing 的长度和原始 scores 列表的长度。 [1]A program stores grades for 3 students across 3 tests in a 2D array and computes the sum of all values.一个程序将 3 名学生在 3 次测试中的成绩存储在二维数组中,并计算所有值之和。
grades = [[85, 90, 78],
[72, 88, 94],
[91, 67, 83]]
total = 0
for row in grades:
for score in row:
total += score
print(total)
print(grades[1][2])
grades[1][2]. Explain which student and which test it refers to (using 0-based counting).写出 grades[1][2] 的值。解释它对应哪位学生和哪次测试(使用从 0 开始的计数)。 [2]total. Show the running total after each row is processed.追踪嵌套循环并写出 total 的最终值。写出每行处理后的累计总和。 [3]for score in row loop body executes in total during the full traversal.写出完整遍历过程中内层 for score in row 循环体共执行了多少次。 [1]A program counts word frequencies in a sentence and then finds words that appear in both sentences using sets.一个程序统计句子中的词频,然后用集合找出两个句子中共同出现的单词。
sentence1 = "the cat sat on the mat"
words1 = sentence1.split()
counts = {}
for word in words1:
if word in counts:
counts[word] += 1
else:
counts[word] = 1
sentence2 = "the dog sat by the tree"
set1 = set(sentence1.split())
set2 = set(sentence2.split())
common = set1 & set2
counts. List all key-value pairs.写出 counts 的最终内容,列出所有键值对。 [3]set1, set2, and common. (Sets are unordered; list elements in any order.)写出 set1、set2 和 common 的内容。(集合无序;元素可按任意顺序列出。) [3]set1 has fewer elements than len(words1).解释为什么 set1 的元素数量少于 len(words1)。 [1]& operator does when applied to two sets.说明 & 运算符对两个集合的操作。 [1]Read each scenario carefully before writing code or traces. Where pseudocode is requested, use the standard block format. Where Python is requested, show correct indentation. Conclude each question with a one-sentence answer to the scenario.动笔前仔细阅读每个场景。伪代码使用标准块格式。Python 须正确缩进。每题以一句完整结论句作答。
A weather station records daily high temperatures for one week: [14, 19, 22, 18, 25, 21, 17]. A program computes the average and finds the first day above a threshold.气象站记录一周每日最高气温:[14, 19, 22, 18, 25, 21, 17]。一个程序计算平均值并找出第一个超过阈值的天。
temps = [14, 19, 22, 18, 25, 21, 17]
threshold = 20
total = 0
for t in temps:
total += t
average = total / len(temps)
found_index = -1
for i in range(len(temps)):
if temps[i] > threshold:
found_index = i
break
average. Show your calculation.计算 average 的值,写出计算过程。 [2]found_index after the loop ends and identify which day (by its value) triggered the break.追踪第二个循环。写出循环结束后 found_index 的值,并说明哪一天的气温(具体数值)触发了 break。 [3]found_index be if the threshold were changed to 30? Explain why.若将阈值改为 30,found_index 会是什么?解释原因。 [2]temps and state the value stored there.说明 temps 的最后一个有效索引,并写出该位置存储的值。 [1]A school library uses a system to track which books are currently checked out. Books are stored in a list; a dictionary maps each student name to a list of books they have borrowed.学校图书馆用一个系统跟踪当前借出的书籍。书籍存储在列表中;字典将每位学生姓名映射到他们借阅的书籍列表。
checked_out = []
checked_out.append("Python Basics")
checked_out.append("Data Science")
checked_out.insert(1, "Algorithms")
checked_out.remove("Data Science")
borrowers = {}
borrowers["Maya"] = ["Python Basics", "Algorithms"]
borrowers["Leon"] = ["Python Basics"]
checked_out after all four list operations.写出全部四次列表操作后 checked_out 的最终内容。 [2]"Python Basics". Use the borrowers dictionary.编写 Python 代码,打印所有借阅过 "Python Basics" 的学生姓名。使用 borrowers 字典。 [3]"Algorithms" from Maya's borrowed list in the dictionary.写一行 Python,将 "Algorithms" 从字典中 Maya 的借阅列表中删除。 [2]A social media platform finds users that two people have in common and users that only one person follows. It also needs to count how many times each tag appears in a list of posts.一个社交媒体平台找出两人共同关注的用户,以及只有一人关注的用户。它还需要统计帖子列表中每个标签出现的次数。
followsA = {"alice", "bob", "carol", "dave"}
followsB = {"bob", "eve", "carol", "frank"}
tags = ["#python", "#cs", "#python", "#data", "#cs", "#python"]
tag_counts = {}
for tag in tags:
if tag in tag_counts:
tag_counts[tag] += 1
else:
tag_counts[tag] = 1
tag_counts loop. State the final contents of tag_counts.追踪 tag_counts 循环。写出 tag_counts 的最终内容。 [3]followsA and followsB and state one property that makes it ideal for computing users-in-common.说明 followsA 和 followsB 使用的数据结构,并说明使其特别适合计算共同用户的一个属性。 [2]3A-AP-14 · 3B-AP-12 · AAP-2.KICS3U A1.5 · A1.6 · A2.3 · ICS4U A3.5Full Syllabus Map in Study Guide: ../Study Guides/Unit_5_Data_Structures.html. CS has no AB standalone diploma exam; AB framing uses CSE2120 outcomes.完整大纲对照见学习指南:../Study Guides/Unit_5_Data_Structures.html。CS 无独立 AB 毕业考;AB 题使用 CSE2120 结果框架。