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 briefly justify your choice in the work space. For short-answer items, write concise answers and show any code traces step by step.本部分包含选择题与短答题。选择题请圈出字母,并在答题空白处简要说明理由。短答题写出简洁答案,并逐步展示代码追踪过程。
A weather sensor records the values 22.4, 65, 1013.2 with no labels. A program then adds the labels "temperature (C)", "humidity (%)", and "pressure (hPa)" and displays: "Average temp today: 22.4 C, expect rain." Which statement best describes the relationship between the raw sensor values and the final display?气象传感器记录了值 22.4, 65, 1013.2,没有标签。程序随后添加标签"温度 (C)"、"湿度 (%)"和"气压 (hPa)"并显示:"今日平均温度:22.4 C,预计有雨。"哪个陈述最准确地描述了原始传感器值与最终显示之间的关系?
A student wants to add a new log entry to log.txt without erasing the existing entries. Which Python file-open mode should they use?一名学生想向 log.txt 添加新日志条目,而不删除现有条目。他们应该使用哪种 Python 文件打开模式?
"r""w""a""x"Consider the CSV file below.考察以下 CSV 文件。
product_id,name,price
101,Notebook,3.50
102,Pen,1.25
103,Ruler,2.00
price field and tries to compute price * 1.13 (tax). The program crashes. Identify the most likely cause and state the fix in one line of Python.程序读取 price 字段并尝试计算 price * 1.13(含税价)。程序崩溃。找出最可能的原因,并用一行 Python 写出修复方法。 [2]The file scores.txt contains one integer per line:文件 scores.txt 每行包含一个整数:
87
92
74
95
88
A student writes the following program to compute the average and write it to summary.txt.一名学生编写以下程序计算平均值并写入 summary.txt。
with open("scores.txt", "r") as f:
scores = [int(line.strip()) for line in f]
average = sum(scores) / len(scores)
with open("summary.txt", "w") as f:
f.write(f"Count: {len(scores)}\n")
f.write(f"Average: {average:.1f}\n")
summary.txt after the program runs.写出程序运行后写入 summary.txt 的确切内容。 [2]line.strip() does and why it is necessary here.解释 line.strip() 的作用,以及为什么在这里是必要的。 [2]"Max: 95" to the existing summary.txt without overwriting it. Write the two lines of Python needed.学生希望在不覆盖 summary.txt 的情况下追加一行 "Max: 95"。写出所需的两行 Python 代码。 [2]with open(...) as f: pattern eliminate the need to call f.close()? Answer in one sentence.为什么 with open(...) as f: 模式不需要调用 f.close()?用一句话回答。 [1]A program reads students.csv using csv.DictReader and prints students who scored above 85.程序使用 csv.DictReader 读取 students.csv,并打印成绩高于 85 的学生。
import csv
with open("students.csv", "r") as f:
reader = csv.DictReader(f)
for row in reader:
if int(row["score"]) > 85:
print(row["name"], row["score"])
The CSV content is:CSV 内容为:
name,grade,score
Alice,11,92
Bob,11,78
Carol,12,95
David,12,82
Eve,11,88
csv.DictReader does differently from csv.reader. State one advantage of using DictReader for named columns.解释 csv.DictReader 与 csv.reader 的不同之处。说明对有名称的列使用 DictReader 的一个优点。 [2]int(row["score"]) be used instead of just row["score"] in the comparison? What error would occur without the conversion?为什么比较中必须使用 int(row["score"]) 而不是直接用 row["score"]?如果不转换会出现什么错误? [2]Show all reasoning. Write SQL in full (SELECT...FROM...WHERE...ORDER BY). For design questions, justify your choice. Two sentences of reasoning earn full marks on explain/justify questions.展示所有推理过程。SQL 须完整书写(SELECT...FROM...WHERE...ORDER BY)。设计题须说明理由。论证/解释题两句推理即可满分。
A school library uses two tables to track books and loans.一所学校图书馆使用两个表来追踪图书和借阅记录。
Table: Books表:Books
book_id | title | author
--------|---------------------|-------------
1 | Python Primer | Smith, J.
2 | Data Science 101 | Lee, C.
3 | Web Basics | Patel, R.
Table: Loans表:Loans
loan_id | book_id | student_name | due_date
--------|---------|--------------|----------
1 | 2 | Alice | 2026-07-01
2 | 1 | Bob | 2026-07-10
3 | 2 | Carol | 2026-07-05
book_id in Loans, rather than repeating the full title in every Loans row? Name this database design principle."Python Primer" 这个书名在 Books 表中只存储一次。为什么将书名存储在 Books 表中一次,并在 Loans 中通过 book_id 引用,比在每条 Loans 记录中重复书名更好?说出这种数据库设计原则的名称。 [2]Use the Books and Loans tables from Q6 to answer the SQL questions below.使用 Q6 中的 Books 和 Loans 表回答以下 SQL 问题。
title and author from Books where book_id = 2.写一个 SQL 查询,从 Books 中返回 book_id = 2 的 title 和 author。 [2]due_date from earliest to latest. State the keyword for ascending sort order.写一个 SQL 查询,返回所有 Loans 行,按 due_date 从早到晚排序。说出升序排列的关键字。 [2]SELECT title WHERE book_id = 1;. Identify the error and write the corrected query.学生写了:SELECT title WHERE book_id = 1;。找出错误并写出更正后的查询。 [2]A music streaming service stores data in two tables: Students (student_id, name, plan) and Plays (play_id, student_id, song_title, play_count). The plan column in Students can be "free" or "premium".一个音乐流媒体服务将数据存储在两个表中:Students(student_id, name, plan)和 Plays(play_id, student_id, song_title, play_count)。Students 表的 plan 列可以是 "free" 或 "premium"。
name and plan of all students on the "premium" plan, sorted alphabetically by name.写一个 SQL 查询,返回所有 "premium" 方案学生的 name 和 plan,按姓名字母顺序排序。 [3]play_count is greater than 100, sorted by play_count from highest to lowest.写一个 SQL 查询,返回 play_count 大于 100 的所有歌曲(song_title),按 play_count 从高到低排序。 [3]Using the Scores table from the Study Guide (columns: score_id, student_id, subject, score), answer the following questions.使用学习指南中的 Scores 表(列:score_id、student_id、subject、score),回答以下问题。
score_id | student_id | subject | score
---------|------------|---------|------
1 | 1 | Math | 92
2 | 1 | CS | 88
3 | 2 | Math | 78
4 | 3 | CS | 95
subject = 'CS'. State the expected result.写一个 SQL 查询,统计 Scores 表中 subject = 'CS' 的行数。说出预期结果。 [2]student_id and score for all rows where subject = 'Math' AND score >= 85.写一个 SQL 查询,返回所有 subject = 'Math' 且 score >= 85 的行的 student_id 和 score。 [2]Read each scenario carefully before answering. Write HTML tags exactly (include angle brackets). Write SQL statements in full. Write Python code with correct indentation. Conclude each question with a one-sentence summary where indicated.动笔前仔细阅读每个场景。HTML 标签须精确书写(包括尖括号)。SQL 语句须完整书写。Python 代码须正确缩进。在指示处以一句完整的结论句作答。
A student is building a simple web page for a school library catalogue. They produce the following HTML, which contains errors.一名学生正在为学校图书馆目录构建一个简单的网页。他们写出了以下 HTML,其中包含错误。
<!DOCTYPE html>
<html>
<head>
<title>Library Catalogue<title>
</head>
<body>
<h1>Library Catalogue</h1>
<p>Welcome to the library.
<a href="books.html">Browse Books</p>
<ul>
<li>Python Primer</li>
<li>Data Science 101
</ul>
</body>
</html>
<head> or <body>) contains the page's visible content, and give one example of something that belongs in the other section.说明哪个 HTML 部分(<head> 或 <body>)包含页面的可见内容,并举一个属于另一部分的内容的例子。 [1]A weather API returns the following JSON response. Study the Python program that processes it.天气接口返回以下 JSON 响应。研究处理它的 Python 程序。
{
"city": "Vancouver",
"temperature": 18.5,
"humidity": 72,
"forecast": {
"tomorrow": "sunny",
"temp_high": 22.0
},
"alerts": ["fog warning", "wind advisory"]
}
import json
response_text = '{"city": "Vancouver", "temperature": 18.5, "humidity": 72, "forecast": {"tomorrow": "sunny", "temp_high": 22.0}, "alerts": ["fog warning", "wind advisory"]}'
data = json.loads(response_text)
city = data["city"]
tomorrow = data["forecast"]["tomorrow"]
first_alert = data["alerts"][0]
print(f"{city}: tomorrow will be {tomorrow}. Alert: {first_alert}")
data["forecast"]["tomorrow"] accesses the value "sunny".逐步解释 data["forecast"]["tomorrow"] 如何访问值 "sunny"。 [2]"alerts" list.写出访问 "alerts" 列表中第二个警告的 Python 表达式。 [1]json.loads() does and what Python type it returns when the input is a JSON object.解释 json.loads() 的作用,以及当输入是 JSON 对象时它返回什么 Python 类型。 [2]A student builds a data pipeline: an API returns student scores as JSON; the program parses them and generates an HTML table to display on a web page.一名学生构建数据管线:接口以 JSON 格式返回学生成绩;程序解析后生成 HTML 表格在网页上显示。
import json
api_response = '''
[
{"name": "Alice", "score": 92},
{"name": "Bob", "score": 78},
{"name": "Carol", "score": 95}
]
'''
students = json.loads(api_response)
html = "<table>\n <tr><th>Name</th><th>Score</th></tr>\n"
for s in students:
html += f" <tr><td>{s['name']}</td><td>{s['score']}</td></tr>\n"
html += "</table>"
print(html)
json.loads(api_response) return in this case: a dict or a list? Explain how you can tell from the JSON structure.json.loads(api_response) 在这里返回什么 Python 类型:字典还是列表?解释如何从 JSON 结构判断。 [2]score >= 90 by wrapping the <tr> tag with a CSS class: <tr class="high">. Modify the for loop (pseudocode or Python) to add this class only when the score meets the threshold.学生希望通过给 <tr> 标签添加 CSS 类 <tr class="high"> 来高亮 score >= 90 的行。修改 for 循环(伪代码或 Python),使其仅在成绩达到阈值时添加此类。 [2]3A-DA-10 · 3A-DA-11 · 3A-DA-12 · DAT-2.CICS4U A3.1 · ICS4C A2.2 · CSE2130Full Syllabus Map in Study Guide: ../Study Guides/Unit_10_Data_Databases_and_the_Web.html. CS has no AB standalone diploma exam; AB framing uses CSE outcomes. SQL questions are ICS4C (college stream); ICS4U students see file I/O and CSV only.完整大纲对照见学习指南:../Study Guides/Unit_10_Data_Databases_and_the_Web.html。CS 无独立 AB 毕业考;AB 题使用 CSE 结果框架。SQL 题属 ICS4C(学院流);ICS4U 学生仅见文件 I/O 和 CSV。