Data, Databases and the Web数据、数据库与网络
Every modern program stores, retrieves, and transmits data. This guide builds the complete picture: what data (data) and information (information) are and how they differ; how to read and write files (file) on disk; how comma-separated values (CSV) let programs share structured data; how relational databases (relational database) organise information into tables (table) linked by keys; how SQL queries (query) let you ask questions of a database with SELECT and WHERE; how HTML assembles a web page (web page); and how web APIs expose data in JSON format so programs can talk to each other over the internet. Code and SQL examples are shown in <pre><code> blocks with Chinese explanations alongside.每个现代程序都需要存储、检索和传输数据(data,数据)。本指南构建完整图景:数据(data,数据)与信息(information,信息)是什么、有何区别;如何从磁盘读写文件(file,文件);逗号分隔值(CSV)如何让程序共享结构化数据;关系数据库(relational database,关系数据库)如何将信息组织成通过键连接的表(table,表);SQL 查询(query,查询)如何通过 SELECT 和 WHERE 向数据库提问;HTML 如何组合网页(web page,网页);以及网络接口(API,接口)如何以 JSON 格式暴露数据,使程序能通过互联网相互通信。
How to use this guide如何使用本指南
Data and databases are treated as a core topic by the US frameworks (CSTA 3A-DA family; AP CSP Big Idea 2 at 17–22% of the exam). Ontario takes a split approach: file I/O sits in ICS4U (university stream, Grade 12), while SQL and web work sit in ICS4C (college stream). BC covers data mainly in the big-data/privacy and Internet-evolution framing of CIS 11/12, with no dedicated SQL standard. Alberta covers files thoroughly in CSE2130 and has a full web-scripting pathway (CSE1210 to CSE3210), but no SQL module in the CSE cluster. Sections §1–§3 (data, files, CSV) are universal. Sections §4–§5 (relational databases, SQL) map most directly to US CSTA, AP CSP, and ON ICS4C. Sections §6–§7 (HTML, JSON/APIs) align with Alberta web scripting and AP CSP Big Idea 2.美国框架将数据和数据库视为核心主题(CSTA 3A-DA 系列;AP CSP 大概念 2 占考试 17–22%)。安大略采用分流方式:文件读写在 ICS4U(大学预科,12 年级),SQL 和网页工作在 ICS4C(学院预科)。BC 主要在 CIS 11/12 的大数据/隐私和互联网演变框架中涵盖数据,没有专用 SQL 标准。阿尔伯塔在 CSE2130 中详细涵盖文件,并有完整的网页脚本路径(CSE1210 至 CSE3210),但 CSE 群集中没有 SQL 模块。§1–§3(数据、文件、CSV)是通用的。§4–§5(关系数据库、SQL)最直接对应美国 CSTA、AP CSP 和安大略 ICS4C。§6–§7(HTML、JSON/接口)与阿尔伯塔网页脚本和 AP CSP 大概念 2 对齐。
| If you are in…如果你在… | Focus on these sections重点学习 | Defer / lighter可推迟 / 减负 | Source依据 |
|---|---|---|---|
| 🇺🇸 US CSTA / AP CSP美国 CSTA / AP CSP | §1 through §7 in full. CSTA 3A-DA-10/11/12 cover data organisation, visualisation and models. AP CSP Big Idea 2 (DAT) topics 2.3 and 2.4 test extracting information from data and using programs with data.§1 至 §7 完整学习。CSTA 3A-DA-10/11/12 涵盖数据组织、可视化和模型。AP CSP 大概念 2(DAT)主题 2.3 和 2.4 考查从数据中提取信息以及将程序与数据结合使用。 | Nothing — AP CSP Big Idea 2 (17–22% of exam) makes all seven sections core for AP students.无——AP CSP 大概念 2(占考试 17–22%)使所有七节对 AP 学生都是核心。 | CSTA K-12 and AP CSP — CSTA 3A-DA-10, 3A-DA-11, 3A-DA-12; AP CSP Big Idea 2 (DAT) topics 2.3, 2.4— CSTA 3A-DA-10、3A-DA-11、3A-DA-12;AP CSP 大概念 2(DAT)主题 2.3、2.4 |
| 🇨🇦 ON — ICS4U (Grade 12 Univ.)安大略 — ICS4U(12 年级大学预科) | §1–§3 (data, file I/O, CSV) map directly to ICS4U A3.1. The file I/O worked examples in §2 are the exact skill assessed. §6 (HTML) for context only.§1–§3(数据、文件读写、CSV)直接对应 ICS4U A3.1。§2 的文件读写例题是被考查的确切技能。§6(HTML)仅作背景。 | §4–§5 (relational databases, SQL) are ICS4C college-stream content — skip for ICS4U floor.§4–§5(关系数据库、SQL)是 ICS4C 学院流内容——ICS4U 基础学生可跳过。 | ON/BC Computer Studies 11-12 — ICS4U A3.1 (file I/O); ICS4C A2.2 (SQL)— ICS4U A3.1(文件读写);ICS4C A2.2(SQL) |
| 🇨🇦 BC — CIS 11 / CIS 12BC — CIS 11 / CIS 12 | §1 (data vs information), §6 (HTML), §7 (JSON/APIs). CIS 11 covers Internet evolution; CIS 12 covers global shifts from online access. File I/O and SQL are enrichment for BC students.§1(数据与信息)、§6(HTML)、§7(JSON/接口)。CIS 11 涵盖互联网演变;CIS 12 涵盖在线访问带来的全球变革。文件读写和 SQL 对 BC 学生为拓展内容。 | BC has no relational-database/SQL standard — §4–§5 are enrichment, not assessed.BC 没有关系数据库/SQL 标准——§4–§5 为拓展内容,不被考查。 | ON/BC Computer Studies 11-12 — BC CS10 big-data/IoT Content; CIS11/12 Internet/online Content bullets— BC CS10 大数据/物联网内容;CIS11/12 互联网/在线内容条目 |
| 🇨🇦 AB — CSE2130 / Web Pathway阿尔伯塔 — CSE2130 / 网页路径 | §1–§3 (data, file I/O) align with CSE2130 outcomes. §6 (HTML) maps to CSE1210/1220 client-side scripting. §7 (JSON/APIs) maps to CSE2210/3210.§1–§3(数据、文件读写)与 CSE2130 结果对齐。§6(HTML)对应 CSE1210/1220 客户端脚本。§7(JSON/接口)对应 CSE2210/3210。 | §4–§5 (relational databases, SQL) — no SQL module in the CSE cluster; treat as enrichment.§4–§5(关系数据库、SQL)——CSE 群集中没有 SQL 模块;作为拓展内容。 | Alberta CTS Computing Science — CSE2130 outcomes 1.4.2, 1.4.5, 1.4.6; CSE1210/1220 descriptions— CSE2130 结果 1.4.2、1.4.5、1.4.6;CSE1210/1220 描述 |
Once you have located your row, use the two cards below for the speed at which you should work through the recommended sections.找到所在行后,用下面两张卡片决定推进速度。
Memorise three things: the difference between data and information; how to open, read, and write a file in Python; and what SELECT/WHERE does in SQL. Read every cram-cheat box. For AP CSP, know that Big Idea 2 tests how programs extract knowledge from data — JSON, CSV, and database queries are all fair game.背熟三件事:数据与信息的区别;如何在 Python 中打开、读取和写入文件;SQL 中 SELECT/WHERE 的作用。读每个速记框。对于 AP CSP,要知道大概念 2 考查程序如何从数据中提取知识——JSON、CSV 和数据库查询都可能考到。
Work through all seven sections in order. The sections build: data → files → CSV → relational tables → SQL → HTML → JSON/APIs. Each concept assumes the previous. For AP CSP, be able to write a program that reads a CSV, filters rows, and outputs a result — that is the synthesis of §2, §3, and §5 combined. For CSTA 3A-DA-11, be able to describe how you would visualise the data you just queried.按顺序学习全部七节。各节层层递进:数据 → 文件 → CSV → 关系表 → SQL → HTML → JSON/接口。每个概念都以前一个为基础。对于 AP CSP,能够编写读取 CSV、过滤行并输出结果的程序——这是 §2、§3 和 §5 的综合。对于 CSTA 3A-DA-11,能够描述如何可视化刚刚查询到的数据。
Data vs Information数据与信息
- Data数据 — raw, unprocessed facts and symbols. Examples:
98.6,"Alice",true, a pixel value. Data has no inherent meaning on its own.— 原始、未经处理的事实和符号。例如:98.6、"Alice"、true、一个像素值。数据本身没有固有含义。 - Information信息 — data that has been processed, organised, or interpreted so it carries meaning. Example: "Alice's body temperature is 98.6°F, which is normal." Context turns data into information.— 经过处理、组织或解释后具有含义的数据。例如:"Alice 的体温是 98.6°F,属于正常。"上下文将数据转变为信息。
- Data types数据类型 — integer, float, string, Boolean, list. Every value stored in a program belongs to a type. CSTA 3A-DA-10: "Evaluate the tradeoffs in how data elements are organized and where data is stored."— 整数、浮点数、字符串、布尔值、列表。程序中存储的每个值都属于一种类型。CSTA 3A-DA-10:"评估数据元素的组织方式和存储位置的权衡。"
A weather station collects three sensor readings every minute: temperature, humidity, pressure. Show the data → information transformation.气象站每分钟采集三个传感器读数:温度、湿度、气压。展示数据 → 信息转换过程。
Raw data (numbers, no meaning without context).原始数据(数字,脱离上下文没有含义)。
22.4, 65, 1013.2
22.6, 64, 1013.0
22.9, 63, 1012.7
The three columns are temperature (°C), humidity (%), and pressure (hPa) — but without column headers these numbers carry no meaning.三列分别是温度(°C)、湿度(%)、气压(hPa)——但如果没有列标题,这些数字毫无意义。
Processing step: label, aggregate, interpret.处理步骤:标注、聚合、解释。
# Python: compute average temperature from a list of readings
readings = [22.4, 22.6, 22.9]
avg_temp = sum(readings) / len(readings)
print(f"Average temperature: {avg_temp:.1f} °C")
# Output: Average temperature: 22.6 °C
sum(readings) adds all values; len(readings) returns the list length; f"..." is a formatted string literal (f-string).sum(readings) 求和,len(readings) 取列表长度,f"..." 是格式化字符串。
Information.信息。 "Average temperature over the last 3 minutes: 22.6 °C. Trend: rising. Humidity dropping. Pressure falling slowly — possible rain within 6 hours." The same raw numbers now carry actionable meaning. CSTA 3A-DA-12: "Create computational models that represent the relationships among different elements of data collected from a phenomenon or process.""过去 3 分钟平均温度:22.6 °C。趋势:上升。湿度下降。气压缓慢下降——6 小时内可能有雨。"同样的原始数字现在具有了可行动的含义。CSTA 3A-DA-12:"创建计算模型,表示从现象或过程中收集的数据的不同元素之间的关系。"
87, 92, 74, 95 with no labels. Which best describes these values?一张电子表格包含值 87, 92, 74, 95,没有标签。哪个最能描述这些值?File Input/Output (Reading and Writing Files)文件输入/输出(读写文件)
- Open打开 — connect a program to a file on disk. Modes:
"r"read,"w"write (overwrites),"a"append. CSE2130 outcome 1.4.2: "opening an existing file."— 将程序连接到磁盘上的文件。模式:"r"读取,"w"写入(覆盖),"a"追加。CSE2130 结果 1.4.2:"打开现有文件。" - Read / Write读取 / 写入 — transfer data between the program and the file. Read brings data in; write sends data out. CSE2130 outcomes 1.4.5 "importing data from a file" and 1.4.4 "exporting data to a file."— 在程序和文件之间传输数据。读取将数据带入;写入将数据送出。CSE2130 结果 1.4.5"从文件导入数据"和 1.4.4"将数据导出到文件"。
- Close关闭 — flush and disconnect. In Python, use
with open(...) as f:— the file closes automatically when the block exits. Always close files to avoid data loss.— 刷新并断开连接。在 Python 中,使用with open(...) as f:——代码块退出时文件自动关闭。始终关闭文件以避免数据丢失。
File scores.txt contains one integer per line. Read all scores, compute the average, and write the result to summary.txt.文件 scores.txt 每行包含一个整数。读取所有成绩,计算平均值,并将结果写入 summary.txt。
scores.txt (sample content).scores.txt(示例内容)。
87
92
74
95
88
Python: read, process, write.Python:读取、处理、写入。
# Read all scores from file
with open("scores.txt", "r") as f:
scores = [int(line.strip()) for line in f]
# Process: compute average
average = sum(scores) / len(scores)
# Write summary to a new file
with open("summary.txt", "w") as f:
f.write(f"Count: {len(scores)}\n")
f.write(f"Average: {average:.1f}\n")
print("Done. summary.txt written.")
open("scores.txt", "r") opens the file in read-only mode; line.strip() removes the trailing newline; int(...) converts the string to an integer; open("summary.txt", "w") creates or overwrites the file in write mode; f.write(...) writes content; \n is the newline character.open("scores.txt", "r") 以只读模式("r",read)打开文件;line.strip() 去除换行符;int(...) 将字符串转为整数;open("summary.txt", "w") 以写入模式("w",write)创建/覆盖文件;f.write(...) 写入内容;\n 是换行符。
Output in summary.txt.summary.txt 中的输出。
Count: 5
Average: 87.2
"a" is append mode — it opens the file and positions the write cursor at the end, so new data is added after existing content. "r" = read only, "w" = write (overwrites everything), "x" = create new file (fails if file exists)."a" 是追加模式——打开文件并将写入游标定位在末尾,因此新数据添加到现有内容之后。"r" = 只读,"w" = 写入(覆盖所有内容),"x" = 创建新文件(文件已存在则失败)。"r" read, "w" write/overwrite, "a" append, "x" exclusive create. Appending means adding to the end without erasing — that is "a".文件模式:"r" 读取,"w" 写入/覆盖,"a" 追加,"x" 独占创建。追加意味着在末尾添加而不删除——那就是 "a"。with open(...) as f: pattern eliminate the need to call f.close()?为什么 Python 的 with open(...) as f: 模式不需要调用 f.close()?with statement is a context manager. When execution leaves the with block — normally or via an exception — Python calls the file's __exit__ method, which flushes and closes the file. This guarantees no data is lost even if an error occurs mid-write.with 语句是一个上下文管理器。当执行离开 with 块时——正常退出或通过异常——Python 调用文件的 __exit__ 方法,该方法刷新并关闭文件。这保证即使写入过程中发生错误,数据也不会丢失。with block handles this automatically via Python's context manager protocol.文件应始终关闭以刷新缓冲区并释放操作系统文件句柄。with 块通过 Python 的上下文管理器协议自动处理这一点。CSV and Structured DataCSV 与结构化数据
- CSV = Comma-Separated ValuesCSV = 逗号分隔值 — a plain-text format where each line is a record and fields within a line are separated by commas. The first line is usually a header row naming each column.— 一种纯文本格式,每行是一条记录,行内字段用逗号分隔。第一行通常是命名每列的标题行。
- Universal exchange format通用交换格式 — spreadsheets, databases, and programs all export/import CSV. It is the most common format for sharing tabular data between systems. CSTA 3A-DA-11 says to "create interactive data visualisations" — CSV is how you get the data in.— 电子表格、数据库和程序都可以导出/导入 CSV。它是系统间共享表格数据最常见的格式。CSTA 3A-DA-11 要求"创建互动数据可视化"——CSV 就是数据的来源方式。
- Python's
csvmodulePython 的csv模块 —csv.readerparses each row into a list;csv.DictReadermaps each row to a dictionary keyed by column name. Always preferDictReaderfor named columns.—csv.reader将每行解析为列表;csv.DictReader将每行映射为以列名为键的字典。对于有名列,始终优先使用DictReader。
File students.csv stores name, grade, and score. Read it and print students who scored above 85.文件 students.csv 存储姓名、年级和成绩。读取它并打印成绩高于 85 的学生。
students.csv content.students.csv 内容。
name,grade,score
Alice,11,92
Bob,11,78
Carol,12,95
David,12,82
Eve,11,88
Python: filter rows where score > 85.Python:过滤成绩 > 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"])
# Output:
# Alice 92
# Carol 95
# Eve 88
import csv loads the built-in csv module; csv.DictReader(f) reads each row as a dictionary (e.g. {"name": "Alice", "grade": "11", "score": "92"}); int(row["score"]) converts the string to an integer before comparing; row["name"] accesses a field by column name.import csv 导入内置 csv 模块;csv.DictReader(f) 将每行读为字典({"name": "Alice", "grade": "11", "score": "92"});int(row["score"]) 将字符串转为整数后比较;row["name"] 通过列名访问字段。
name,grade,score. What is this row called?在 CSV 文件中,第一行是 name,grade,score。这一行叫什么?score field to 85 numerically, what must you do first?程序读取一个 CSV,所有值都是字符串。要将 score 字段与 85 进行数值比较,必须先做什么?"92" > 85 would raise a TypeError in Python 3 (or give wrong results in Python 2). You must first convert: int(row["score"]) > 85. This is the most common bug when processing CSV data.CSV 值始终作为字符串读取。在 Python 3 中,比较 "92" > 85 会引发 TypeError(在 Python 2 中会给出错误结果)。必须先转换:int(row["score"]) > 85。这是处理 CSV 数据时最常见的错误。int() or float() before numeric comparison.Python 3 中用 > 比较字符串和整数会引发 TypeError。CSV 字段始终是字符串——在数值比较之前先用 int() 或 float() 转换。Relational Databases and Tables关系数据库与表
- Table表 — a two-dimensional grid of data: rows (records) and columns (fields/attributes). Like a CSV, but stored in the database engine.— 二维数据网格:行(记录)和列(字段/属性)。类似 CSV,但存储在数据库引擎中。
- Primary key主键 — a column (or set of columns) whose value uniquely identifies each row. Example:
student_idin a Students table. No two rows may share the same primary key.— 唯一标识每行的列(或列集合)。例如:Students 表中的student_id。任何两行不得共享相同的主键。 - Foreign key外键 — a column in one table that references the primary key of another table. This is the "relational" part — it links two tables together. CSTA 3A-DA-10: "Evaluate the tradeoffs in how data elements are organized."— 一个表中引用另一个表主键的列。这就是"关系"的部分——它将两个表连接在一起。CSTA 3A-DA-10:"评估数据元素组织方式的权衡。"
- Normalisation规范化 — organising data to reduce duplication. Instead of repeating a student's name in every grade record, store the name once in the Students table and reference it by ID.— 组织数据以减少重复。与其在每条成绩记录中重复学生姓名,不如在 Students 表中存储一次姓名并通过 ID 引用。
Design a relational database for student grades. One table stores students; another stores assignments. Link them with a foreign key.为学生成绩设计一个关系数据库。一个表存储学生;另一个表存储作业。用外键将它们连接。
Table 1: Students (primary key = student_id).表 1:Students(主键 = student_id)。
| student_id | name | grade |
|---|---|---|
| 1 | Alice | 11 |
| 2 | Bob | 11 |
| 3 | Carol | 12 |
Table 2: Scores (primary key = score_id; foreign key = student_id references Students).表 2:Scores(主键 = score_id;外键 = student_id 引用 Students)。
| score_id | student_id | subject | score |
|---|---|---|---|
| 1 | 1 | Math | 92 |
| 2 | 1 | CS | 88 |
| 3 | 2 | Math | 78 |
| 4 | 3 | CS | 95 |
Alice's name is stored once in Students. Her two score rows in Scores reference her by student_id = 1. If her name changes, we update it in one place only — that is the benefit of normalisation. Without a relational database, every score row would repeat her full name, wasting space and risking inconsistency.Alice 的姓名在 Students 中只存储一次。她在 Scores 中的两条成绩行通过 student_id = 1 引用她。如果她的姓名变了,只需在一个地方更新——这就是规范化的好处。没有关系数据库,每条成绩行都要重复她的全名,浪费空间且容易出现不一致。
student_id that references the student_id column in the Students table. What is student_id called in the Scores table?Scores 表有一列 student_id,它引用 Students 表中的 student_id 列。student_id 在 Scores 表中叫什么?SQL Basics: SELECT and WHERESQL 基础:SELECT 与 WHERE
SELECT— choose which columns to return.SELECT *returns all columns;SELECT name, scorereturns only those two.— 选择要返回的列。SELECT *返回所有列;SELECT name, score只返回那两列。FROM— specify the table to query. Every SELECT needs a FROM.— 指定要查询的表。每个 SELECT 都需要 FROM。WHERE— filter rows. Only rows where the condition is true are returned. Operators:=,<,>,<=,>=,!=,LIKE,AND,OR.— 过滤行。只返回条件为真的行。运算符:=、<、>、<=、>=、!=、LIKE、AND、OR。ORDER BY— sort the results.ORDER BY score DESCsorts highest-first;ASCis lowest-first (the default).— 对结果排序。ORDER BY score DESC按从高到低排序;ASC从低到高(默认)。
;. ICS4C A2.2 names "relational database via SQL" explicitly. CSTA 3A-DA-10 says to "evaluate the tradeoffs in how data elements are organized and where data is stored" — SQL is the access layer on top of the organised storage.SQL 关键字不区分大小写,但约定大写。SQL 语句以 ; 结尾。ICS4C A2.2 明确点名"通过 SQL 的关系数据库"。CSTA 3A-DA-10 要求"评估数据元素组织方式和存储位置的权衡"——SQL 是有组织存储之上的访问层。
Using the two tables from §4, write SQL queries to answer common questions.使用 §4 中的两个表,编写 SQL 查询来回答常见问题。
Query 1: Get all students.查询 1:获取所有学生。
SELECT * FROM Students;
SELECT * selects all columns; FROM Students specifies the Students table. All three rows are returned.SELECT * 选择所有列,FROM Students 从 Students 表查询。返回所有三行。
Query 2: Get names and scores where score > 85.查询 2:获取成绩 > 85 的姓名和成绩。
SELECT student_id, subject, score
FROM Scores
WHERE score > 85
ORDER BY score DESC;
WHERE score > 85 filters rows to those with a score above 85; ORDER BY score DESC sorts the results from highest to lowest (DESC = descending).WHERE score > 85 过滤条件;ORDER BY score DESC 按成绩从高到低排序(DESC = descending,降序)。
Expected result (from the §4 data):预期结果(来自 §4 数据):
| student_id | subject | score |
|---|---|---|
| 3 | CS | 95 |
| 1 | Math | 92 |
| 1 | CS | 88 |
Query 3: Count how many CS scores exist.查询 3:统计 CS 成绩的条数。
SELECT COUNT(*) FROM Scores WHERE subject = 'CS';
COUNT(*) counts the number of matching rows. Result: 2 (Carol and Alice each have one CS record).COUNT(*) 计算匹配行的数量。结果:2(Carol 和 Alice 各有一条 CS 记录)。
name column from the Students table where the grade is 11?哪个 SQL 查询从 Students 表中只返回 grade 为 11 的 name 列?SELECT <columns> FROM <table> WHERE <condition>. Only option D has all three parts correct: column = name, table = Students, filter = grade = 11.完整的 SELECT 需要:SELECT <列> FROM <表> WHERE <条件>。只有选项 D 三个部分都正确:列 = name,表 = Students,过滤 = grade = 11。SELECT columns FROM table WHERE condition;. You must include FROM to name the table. Option A has no WHERE. Options B and C are missing FROM or SELECT columns.SQL SELECT 语法:SELECT 列 FROM 表 WHERE 条件;。必须包含 FROM 来命名表。选项 A 没有 WHERE。选项 B 和 C 缺少 FROM 或 SELECT 列。ORDER BY score DESC sorts the results in what order?在 SQL 中,ORDER BY score DESC 以什么顺序排序结果?DESC stands for descending — highest to lowest. ASC (ascending) is lowest to highest and is the default. So ORDER BY score DESC puts the highest score first in the result set.DESC 代表降序——从高到低。ASC(升序)从低到高,是默认值。所以 ORDER BY score DESC 将最高分放在结果集的第一位。HTML and the Web: An IntroductionHTML 与网络:入门介绍
- HTML = HyperText Markup LanguageHTML = 超文本标记语言 — the standard language for creating web pages. A browser reads an HTML file and renders it visually. Alberta CSE1210: "Students are introduced to Internet computing through the use of one or more Web-specific markup languages."— 创建网页的标准语言。浏览器读取 HTML 文件并将其可视化渲染。阿尔伯塔 CSE1210:"学生通过使用一种或多种网络专用标记语言了解互联网计算。"
- Tags标签 — HTML uses paired tags:
<tag>content</tag>. Opening tag + content + closing tag. Self-closing tags (e.g.<br>,<img>) have no content.— HTML 使用成对标签:<标签>内容</标签>。开始标签 + 内容 + 结束标签。自闭合标签(如<br>、<img>)没有内容。 - Structure: head + body结构:head + body — every HTML page has a
<head>(metadata: title, charset, links to CSS) and a<body>(visible content).— 每个 HTML 页面都有一个<head>(元数据:标题、字符集、CSS 链接)和一个<body>(可见内容)。 - Key tags to know需要了解的关键标签 —
<h1>–<h6>headings,<p>paragraph,<a href="...">link,<ul>/<li>list,<table>table,<form>form,<input>input field.—<h1>–<h6>标题,<p>段落,<a href="...">链接,<ul>/<li>列表,<table>表格,<form>表单,<input>输入框。
Write an HTML page that displays the Students table from §4 as a formatted web table.编写一个 HTML 页面,将 §4 的 Students 表显示为格式化的网页表格。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Student Records</title>
</head>
<body>
<h1>Students</h1>
<table border="1">
<tr>
<th>ID</th><th>Name</th><th>Grade</th>
</tr>
<tr><td>1</td><td>Alice</td><td>11</td></tr>
<tr><td>2</td><td>Bob</td><td>11</td></tr>
<tr><td>3</td><td>Carol</td><td>12</td></tr>
</table>
</body>
</html>
<!DOCTYPE html> declares the document type as HTML5; <head> holds metadata (<meta charset="UTF-8"> sets the character encoding; <title> sets the browser-tab title); <body> contains the visible content; <table> creates a table; <tr> is a table row; <th> is a header cell; <td> is a data cell.<!DOCTYPE html> 声明文档类型为 HTML5;<head> 含元数据(<meta charset="UTF-8"> 设置字符编码,<title> 设置浏览器标签标题);<body> 含可见内容;<table> 创建表格;<tr> 是表格行(table row);<th> 是表头单元格(table header);<td> 是普通数据单元格(table data)。
<a href="https://example.com">Click here</a> create?在 HTML 中,<a href="https://example.com">点击这里</a> 创建什么?<a> tag (anchor) creates a hyperlink. The href attribute specifies the destination URL. The content between the tags ("Click here") is the visible link text. Clicking it navigates to example.com.<a> 标签(锚点)创建超链接。href 属性指定目标 URL。标签之间的内容("点击这里")是可见的链接文本。点击它导航到 example.com。<a> tag with href creates a hyperlink, not an image (<img>), form (<form>), or paragraph (<p>).<a> 标签加 href 创建超链接,不是图片(<img>)、表单(<form>)或段落(<p>)。<body> element contains all visible page content. The <head> holds metadata (title, charset, CSS links — not rendered as page content). <title> sets the browser tab title (shown in the tab, not the page). <meta> provides machine-readable metadata.<body> 元素包含所有可见的页面内容。<head> 存放元数据(标题、字符集、CSS 链接——不渲染为页面内容)。<title> 设置浏览器标签标题(显示在标签中,不在页面上)。<meta> 提供机器可读的元数据。Data on the Web: JSON and APIs网络上的数据:JSON 与接口
- JSON = JavaScript Object NotationJSON = JavaScript 对象表示法 — a lightweight text format for storing and transmitting structured data. Looks like Python dictionaries and lists. Human-readable and machine-parseable. CSTA 3A-DA-12: "Create computational models that represent the relationships among different elements of data" — JSON is how those models travel over the web.— 用于存储和传输结构化数据的轻量级文本格式。看起来像 Python 字典和列表。人类可读且机器可解析。CSTA 3A-DA-12:"创建表示数据不同元素之间关系的计算模型"——JSON 就是这些模型在网络上传输的方式。
- JSON syntaxJSON 语法 — keys must be double-quoted strings; values can be strings, numbers, booleans (
true/false),null, arrays ([]), or nested objects ({}).— 键必须是双引号字符串;值可以是字符串、数字、布尔值(true/false)、null、数组([])或嵌套对象({})。 - API = Application Programming Interface接口 = 应用程序编程接口 — a set of rules that lets one program request data or actions from another. Web APIs expose data over HTTP; the response is usually JSON. Alberta CSE2210/3210 (Client-side Scripting) and AB CSE1220 introduce this web-programming context.— 让一个程序向另一个程序请求数据或操作的一组规则。Web 接口通过 HTTP 暴露数据;响应通常是 JSON。阿尔伯塔 CSE2210/3210(客户端脚本)和 AB CSE1220 介绍这种网页编程背景。
- Python:
jsonmodulePython:json模块 —json.loads(text)parses a JSON string into a Python dict/list;json.dumps(obj)serialises a Python object back to a JSON string.—json.loads(text)将 JSON 字符串解析为 Python 字典/列表;json.dumps(obj)将 Python 对象序列化回 JSON 字符串。
A weather API returns this JSON response. Extract the city name and temperature and print them.天气接口返回以下 JSON 响应。提取城市名称和温度并打印。
Sample JSON response (the text the API sends back).示例 JSON 响应(接口返回的文本)。
{
"city": "Toronto",
"country": "CA",
"temperature": 22.4,
"humidity": 65,
"conditions": ["cloudy", "mild"],
"forecast": {
"tomorrow": "rain",
"temp_high": 18.0
}
}
Python: parse and extract fields.Python:解析并提取字段。
import json
# Simulated API response text
response_text = '''
{
"city": "Toronto",
"country": "CA",
"temperature": 22.4,
"humidity": 65,
"conditions": ["cloudy", "mild"],
"forecast": {"tomorrow": "rain", "temp_high": 18.0}
}
'''
# Parse JSON string into a Python dictionary
data = json.loads(response_text)
# Access fields
city = data["city"]
temp = data["temperature"]
tomorrow = data["forecast"]["tomorrow"]
print(f"{city}: {temp}°C, tomorrow: {tomorrow}")
# Output: Toronto: 22.4°C, tomorrow: rain
import json loads the json module; json.loads(...) parses a JSON string into a Python dictionary (loads = load string); data["city"] accesses a value by key; data["forecast"]["tomorrow"] accesses a nested object by first retrieving the "forecast" dictionary, then its "tomorrow" key.import json 导入 json 模块;json.loads(...) 将 JSON 字符串(loads = load string)转为 Python 字典;data["city"] 通过键访问字典值;data["forecast"]["tomorrow"] 访问嵌套对象——先取 "forecast" 字典,再取其 "tomorrow" 键。
"name": "Alice" is valid JSON. Single quotes and unquoted keys are not allowed in JSON (though they are valid in Python dicts and JavaScript objects).在 JSON 中,键必须是双引号字符串。值也必须使用双引号(不是单引号)。因此只有 "name": "Alice" 是有效的 JSON。单引号和不带引号的键在 JSON 中不被允许(尽管在 Python 字典和 JavaScript 对象中有效)。data = {"scores": [88, 92, 75]} in Python, what does data["scores"][1] evaluate to?给定 Python 中 data = {"scores": [88, 92, 75]},data["scores"][1] 的值是什么?data["scores"] accesses the list [88, 92, 75]. Then [1] accesses index 1 of that list. Python lists are 0-indexed, so index 0 = 88, index 1 = 92, index 2 = 75. Result: 92.data["scores"] 访问列表 [88, 92, 75]。然后 [1] 访问该列表的索引 1。Python 列表从 0 开始索引,所以索引 0 = 88,索引 1 = 92,索引 2 = 75。结果:92。data["scores"] returns the list [88, 92, 75]. (2) [1] on that list returns the item at index 1. Python is 0-indexed: index 0 = 88, index 1 = 92.两步:(1) data["scores"] 返回列表 [88, 92, 75]。(2) 对该列表 [1] 返回索引 1 处的项。Python 从 0 开始索引:索引 0 = 88,索引 1 = 92。Exam Strategy and Common Pitfalls考试策略与常见陷阱
- Data vs information distinction.数据与信息的区别。 Examiners frequently ask: "Is this data or information? Explain." The answer always hinges on context: raw unlabelled values are data; values with meaning attached (label, unit, interpretation) are information. State the difference explicitly.考官常问:"这是数据还是信息?请解释。"答案总是取决于上下文:未标注的原始值是数据;附有含义(标签、单位、解释)的值是信息。明确说明区别。
- CSV type-conversion pitfall.CSV 类型转换陷阱。 Every value read from a CSV is a string. Always convert with
int()orfloat()before numeric comparison or arithmetic. Forgetting this is the single most common file-processing bug.从 CSV 读取的每个值都是字符串。在数值比较或算术之前,始终用int()或float()转换。忘记这一点是最常见的文件处理错误。 - File modes.文件模式。 Know
"r"(read),"w"(write — overwrites),"a"(append). On an exam, if the question says "add a new record without deleting existing ones," the answer is append mode ("a").了解"r"(读取)、"w"(写入——覆盖)、"a"(追加)。在考试中,如果题目说"添加新记录而不删除现有记录",答案是追加模式("a")。
- Primary vs foreign key.主键与外键。 Primary key = unique identifier for rows in its own table. Foreign key = references the primary key in another table. Mixing these up is a common error. Remember: foreign key creates the link between tables.主键 = 本表行的唯一标识符。外键 = 引用另一个表的主键。混淆这两者是常见错误。记住:外键创建表之间的链接。
- SQL clause order.SQL 子句顺序。 Always: SELECT → FROM → WHERE → ORDER BY. You cannot write WHERE before FROM. Missing FROM is the most common SQL syntax error on exams.始终:SELECT → FROM → WHERE → ORDER BY。不能在 FROM 之前写 WHERE。缺少 FROM 是考试中最常见的 SQL 语法错误。
- Ontario divergence.安大略分流。 If you are in ICS4U (university stream), SQL is ICS4C (college stream) content — you are not assessed on SQL in ICS4U. Your file I/O standard is A3.1. Know which course you are in.如果你在 ICS4U(大学流),SQL 是 ICS4C(学院流)内容——ICS4U 不考查 SQL。你的文件读写标准是 A3.1。了解你在哪门课程中。
- Paired tags.成对标签。 Every opening tag needs a closing tag (except self-closing ones like
<br>). On a "find the error in this HTML" question, missing closing tags are the most common planted bug.每个开始标签都需要一个结束标签(除了<br>等自闭合标签)。在"找出 HTML 中的错误"题中,缺少结束标签是最常见的预设错误。 - JSON double quotes only.JSON 只用双引号。 JSON keys and string values must use double quotes, not single quotes. On a "is this valid JSON?" question, single quotes or unquoted keys make it invalid.JSON 键和字符串值必须使用双引号,而非单引号。在"这是有效的 JSON 吗?"题中,单引号或不带引号的键使其无效。
- data vs information for AP CSP.AP CSP 的数据与信息。 AP CSP Big Idea 2 (17–22% of the exam) tests whether you understand that programs can extract knowledge from raw data. When a question shows a JSON payload and asks "what knowledge can be generated from this data?" — apply the data → information transformation from §1.AP CSP 大概念 2(占考试 17–22%)测试你是否理解程序可以从原始数据中提取知识。当题目展示 JSON 载荷并问"可以从这些数据中生成什么知识?"——应用 §1 的数据 → 信息转换。
- State the tradeoff explicitly.明确说明权衡。 CSTA 3A-DA-10 says to "evaluate tradeoffs." On a question about CSV vs database, do not just say "databases are better." State both sides: CSV is simpler and portable; a database supports complex queries and avoids duplicate data. Then state the recommendation for the given scenario.CSTA 3A-DA-10 要求"评估权衡"。在关于 CSV 与数据库的题中,不要只说"数据库更好"。说明两方面:CSV 更简单且可移植;数据库支持复杂查询并避免数据重复。然后针对给定场景说明建议。
- Show the full SQL statement.展示完整的 SQL 语句。 On SQL questions, always write the complete statement including SELECT, FROM, and (if required) WHERE. Partial statements score partial marks at best.在 SQL 题中,始终写出完整语句,包括 SELECT、FROM 和(如需)WHERE。不完整的语句最多得部分分。
Flashcards闪卡
Practice Quiz综合测验
37 from a CSV file. What Python type does the variable hold immediately after reading?程序从 CSV 文件中读取数字 37。读取后变量立即持有什么 Python 类型?int(row["score"]) or float(row["score"]) before doing math.CSV 文件是纯文本。从 CSV 读取的每个值——包括数字——都是字符串(str),直到你转换它。在进行数学运算之前使用 int(row["score"]) 或 float(row["score"])。student_id, name, grade. A Scores table has columns score_id, student_id, subject, score. What is student_id called in the Scores table?Students 表有列 student_id、name、grade。Scores 表有列 score_id、student_id、subject、score。student_id 在 Scores 表中叫什么?student_id references the primary key of the Students table. A column that references another table's primary key is a foreign key. It creates the relational link between the two tables.在 Scores 表中,student_id 引用 Students 表的主键。引用另一个表主键的列是外键。它创建两个表之间的关系链接。<a> (anchor) tag with the href attribute creates a hyperlink. <link> is used in the <head> to link external CSS stylesheets. <p> is a paragraph. There is no <src> tag.<a>(锚点)标签加 href 属性创建超链接。<link> 在 <head> 中用于链接外部 CSS 样式表。<p> 是段落。没有 <src> 标签。{"name": "Bob", "scores": [78, 85, 91]}. What does data["scores"][2] evaluate to in Python?JSON 对象为 {"name": "Bob", "scores": [78, 85, 91]}。在 Python 中 data["scores"][2] 的值是什么?data["scores"] returns the list [78, 85, 91]. Python lists are 0-indexed: index 0 = 78, index 1 = 85, index 2 = 91. So data["scores"][2] = 91.data["scores"] 返回列表 [78, 85, 91]。Python 列表从 0 开始索引:索引 0 = 78,索引 1 = 85,索引 2 = 91。所以 data["scores"][2] = 91。Readiness Checklist准备就绪清单
Tick each item when you can do it cold, without notes, on a first attempt.能在无笔记、首次尝试下完成,再勾选每一项。
- Explain the difference between data and information with a concrete example, and state why context is what converts data into information. 🇺🇸 CSTA 3A-DA-10 / AP CSP DAT用具体例子解释数据和信息的区别,并说明为什么上下文将数据转变为信息。🇺🇸 CSTA 3A-DA-10 / AP CSP DAT
- Write a Python program that opens a text file in read mode, reads all lines, computes the average of the numbers, and writes the result to a second file. 🇨🇦 ON ICS4U A3.1 / AB CSE2130编写一个 Python 程序,以读取模式打开文本文件,读取所有行,计算数字的平均值,并将结果写入第二个文件。🇨🇦 ON ICS4U A3.1 / AB CSE2130
- State the three Python file modes ("r", "w", "a"), explain what each does, and identify which to use if you want to add a new record to an existing log file. 🇨🇦 AB CSE2130 outcome 1.4.6说明三种 Python 文件模式("r"、"w"、"a"),解释每种的作用,并识别向现有日志文件添加新记录时应使用哪种。🇨🇦 AB CSE2130 结果 1.4.6
- Read a CSV with csv.DictReader, filter rows where a numeric field exceeds a threshold, and explain why int() conversion is required before the comparison. 🇺🇸 CSTA 3A-DA-11 / AP CSP DAT-2使用 csv.DictReader 读取 CSV,过滤数值字段超过阈值的行,并解释为什么比较前需要 int() 转换。🇺🇸 CSTA 3A-DA-11 / AP CSP DAT-2
- Define primary key and foreign key, and draw or describe the relationship between a Students table and a Scores table linked by student_id. 🇺🇸 CSTA 3A-DA-10 / 🇨🇦 ON ICS4C A2.2定义主键和外键,并画出或描述通过 student_id 连接的 Students 表和 Scores 表之间的关系。🇺🇸 CSTA 3A-DA-10 / 🇨🇦 ON ICS4C A2.2
- Write a complete SQL SELECT statement with a WHERE filter and an ORDER BY clause; identify the correct clause order (SELECT → FROM → WHERE → ORDER BY). 🇨🇦 ON ICS4C A2.2 / 🇺🇸 CSTA 3A-DA-10写出带 WHERE 过滤和 ORDER BY 子句的完整 SQL SELECT 语句;识别正确的子句顺序(SELECT → FROM → WHERE → ORDER BY)。🇨🇦 ON ICS4C A2.2 / 🇺🇸 CSTA 3A-DA-10
- Write a minimal valid HTML page with a title, a heading, and a two-column table. Identify the roles of <head>, <body>, <table>, <tr>, <th>, and <td>. 🇨🇦 AB CSE1210/1220编写一个包含标题、标题和两列表格的最小有效 HTML 页面。识别 <head>、<body>、<table>、<tr>、<th> 和 <td> 的角色。🇨🇦 AB CSE1210/1220
- Parse a JSON string with json.loads(), access a nested field (e.g., data["forecast"]["tomorrow"]), and explain the difference between json.loads() and json.dumps(). 🇺🇸 CSTA 3A-DA-12 / AP CSP DAT-2使用 json.loads() 解析 JSON 字符串,访问嵌套字段(如 data["forecast"]["tomorrow"]),并解释 json.loads() 和 json.dumps() 的区别。🇺🇸 CSTA 3A-DA-12 / AP CSP DAT-2
- State the three JSON syntax rules: (1) keys must be double-quoted strings, (2) no single quotes, (3) no trailing commas. Identify at least one error in a given invalid JSON snippet. 🇺🇸 AP CSP DAT说明三条 JSON 语法规则:(1) 键必须是双引号字符串,(2) 不允许单引号,(3) 不允许尾随逗号。在给定的无效 JSON 片段中识别至少一个错误。🇺🇸 AP CSP DAT
- Explain the Ontario divergence: why SQL/relational databases are in ICS4C (college stream) but not ICS4U (university stream), and what ICS4U students study instead (file I/O, A3.1). 🇨🇦 ON ICS4U A3.1 / ICS4C A2.2解释安大略分流:为什么 SQL/关系数据库在 ICS4C(学院流)而非 ICS4U(大学流),以及 ICS4U 学生转而学习什么(文件读写,A3.1)。🇨🇦 ON ICS4U A3.1 / ICS4C A2.2
- Describe the data → information transformation pipeline for AP CSP Big Idea 2: raw data enters a program, the program processes it, and the output is knowledge (information). Give one example showing each stage. 🇺🇸 AP CSP DAT-2 / CSTA 3A-DA-11/12描述 AP CSP 大概念 2 的数据 → 信息转换管线:原始数据进入程序,程序处理它,输出是知识(信息)。给出一个显示每个阶段的例子。🇺🇸 AP CSP DAT-2 / CSTA 3A-DA-11/12
What This Feeds Into本单元的去向
Data, databases and the web are the infrastructure that every modern program rests on. The skills here — reading files, parsing CSV and JSON, querying a database, building a web page — underpin the AP CSP Create Performance Task (your program must handle real data), the CSTA 3A-DA standards, and the data-handling sections of Ontario's Grade 12 Computer Science courses. No AP CSA database or web guide exists in this repo yet; the section below focuses on within-series and AP CSP connections.数据、数据库和网络是每个现代程序所依赖的基础设施。这里的技能——读取文件、解析 CSV 和 JSON、查询数据库、构建网页——支撑 AP CSP 创作绩效任务(程序必须处理真实数据)、CSTA 3A-DA 标准和安大略 12 年级计算机科学课程的数据处理部分。本仓库中目前没有 AP CSA 数据库或网页指南;以下部分重点介绍系列内和 AP CSP 的连接。
Within High School Computer Science.在 HS Computer Science 内部。
Unit 2 (Programming Fundamentals) gave you variables, data types, and I/O — this unit shows where that data lives on disk and in databases. Unit 5 (Data Structures) shows how to organise data in memory (lists, dictionaries); this unit shows how to persist it on disk or transmit it over the web. Unit 9 (Boolean Logic) underpins the WHERE clause logic you used in §5. The data skills here synthesise material from across the series into a complete pipeline: file → parse → filter → display.第 2 单元(编程基础)给了你变量、数据类型和 I/O——本单元展示这些数据在磁盘和数据库中的存储位置。第 5 单元(数据结构)展示如何在内存中组织数据(列表、字典);本单元展示如何将其持久化到磁盘或通过网络传输。第 9 单元(布尔逻辑)支撑你在 §5 中使用的 WHERE 子句逻辑。这里的数据技能将整个系列的材料综合成一个完整的管线:文件 → 解析 → 过滤 → 显示。
AP CSP feeder (no link — no AP database guide in this repo).AP CSP 衔接(无链接——本仓库中没有 AP 数据库指南)。
AP CSP Big Idea 2 (Data — DAT) is weighted at 17–22% of the exam and directly tests the skills in this guide: extracting information from data (topics 2.3, 2.4), understanding how programs generate knowledge from raw inputs, and evaluating tradeoffs in data storage and representation (CSTA 3A-DA-10). The Create Performance Task requires you to write a program that processes data — the CSV-reading and JSON-parsing patterns in §2, §3, and §7 are the practical skills that task demands. There is no AP CSA database or web guide in this repo; students moving to AP CSA should treat this unit as enrichment background for data persistence concepts that AP CSA covers through file I/O and 2D arrays.AP CSP 大概念 2(数据——DAT)占考试 17–22%,直接考查本指南中的技能:从数据中提取信息(主题 2.3、2.4)、理解程序如何从原始输入生成知识,以及评估数据存储和表示的权衡(CSTA 3A-DA-10)。创作绩效任务要求编写处理数据的程序——§2、§3 和 §7 中的 CSV 读取和 JSON 解析模式是该任务要求的实践技能。本仓库中没有 AP CSA 数据库或网页指南;转向 AP CSA 的学生应将本单元视为 AP CSA 通过文件 I/O 和二维数组涵盖的数据持久化概念的拓展背景。