📚 Edexcel A-Level Programming Essentials: Data, Control and Algorithms | Edexcel A-Level 编程核心:数据、控制与算法
Programming questions in Edexcel A-Level Computer Science are never only about writing code. You are being tested on whether you can choose sensible data types, control the flow of a program with selection and iteration, break a problem into subroutines, and apply standard algorithms such as linear search, binary search, bubble sort and merge sort. Equally important, you must be able to express all of this in clear, exam-standard pseudocode that a marker can follow line by line.
在 Edexcel A-Level 计算机科学中,编程题从来不只是"写代码"。考官真正考查的是:你能否选择合理的数据类型、用选择与循环控制程序流程、把问题拆分成子程序,并应用线性查找、二分查找、冒泡排序、归并排序等标准算法。同样重要的是,你必须能用清晰、符合考试规范的伪代码把这些思路表达出来,让阅卷老师能逐行读懂。
This guide rebuilds the core programming content of the specification into one revision path: paradigms, data types and variables, scope, operators, selection, iteration, subroutines, data structures, standard algorithms, efficiency, validation and testing, and finally exam technique. Each section pairs the English terminology that appears in papers with the explanation you need in order to answer confidently.
本指南把考纲中的编程核心内容整理成一条完整的复习路径:编程范式、数据类型与变量、作用域、运算符、选择结构、循环结构、子程序、数据结构、标准算法、算法效率、校验与测试,最后是考试技巧。每一节都把试卷中出现的英文术语与"答题必备"的解释配对呈现,帮助你从容作答。
1. Programming Paradigms | 编程范式
A programming paradigm is a style or approach to structuring a program. Edexcel expects you to identify four paradigms - procedural, object-oriented, event-driven and functional - and to compare their strengths and weaknesses for a given scenario. Typical exam wording is: "State the paradigm used by this program and justify your answer." Your justification must refer to a feature of the code, not just name the paradigm.
编程范式是组织程序的一种风格或方法。Edexcel 要求你识别四种范式:过程式、面向对象、事件驱动和函数式,并能针对给定情境比较它们的优缺点。常见的考题表述是:"指出该程序使用的范式并说明理由。"你的理由必须指向代码中的具体特征,而不能只写出范式名称。
Procedural programming breaks a solution into a sequence of instructions and named subroutines. It is easy to read, easy to trace and maps well onto algorithm questions, which is why most exam pseudocode is procedural. Its weakness is that data and the code that manipulates it are separate, so large programs become hard to maintain and data can be modified from anywhere.
过程式编程把解法拆分为一系列指令和具名子程序。它易读、易追踪,与算法题的思维方式高度契合,因此试卷中的伪代码大多采用过程式。它的缺点是数据与操作数据的代码相分离,程序规模变大后可维护性差,且数据可能在任何位置被修改。
Object-oriented programming (OOP) models a system as classes and objects. A class defines attributes (data) and methods (behaviour); an object is an instance of a class. Encapsulation hides attributes behind methods, inheritance lets a subclass reuse and extend a parent class, and polymorphism allows the same method call to behave differently depending on the object. OOP suits systems with many similar entities, such as a booking system with Customer, Booking and Payment classes.
面向对象编程(OOP)把系统建模为类和对象。类定义属性(数据)与方法(行为),对象是类的实例。封装把属性隐藏在方法之后;继承让子类复用并扩展父类;多态使同一个方法调用因对象不同而表现不同。OOP 适合存在大量相似实体的系统,例如包含 Customer、Booking、Payment 等类的预订系统。
Event-driven programming waits for events such as a mouse click, a key press, a timer expiring or data arriving from a sensor. The program is controlled by an event loop and a set of event handlers; nothing happens until an event fires. Functional programming treats computation as the evaluation of pure functions that avoid changing state, supporting higher-order functions, immutable data and recursion. It is valued for parallel processing and for reducing side effects.
事件驱动编程等待事件发生,例如鼠标点击、按键、定时器到期或传感器数据到达。程序由事件循环和一组事件处理程序控制;没有事件触发,程序不会执行相应逻辑。函数式编程把计算视为对纯函数的求值,尽量避免改变状态,支持高阶函数、不可变数据和递归,其优势在于便于并行处理并减少副作用。
| Paradigm | Key idea | Typical use |
|---|---|---|
| Procedural | sequence of instructions and subroutines | calculation programs, algorithm questions |
| Object-oriented | classes, objects, encapsulation, inheritance | booking, banking, games with many entities |
| Event-driven | event loop plus event handlers | GUIs, embedded systems, web front ends |
| Functional | pure functions, immutable data, recursion | data processing, parallel computation |
When justifying a choice, link the paradigm to the requirements: use OOP when the scenario mentions many records of the same kind with shared behaviour, use event-driven when it mentions a user interface or sensors, and use procedural when it emphasises a fixed calculation followed by output.
说明选择理由时,要把范式与需求挂钩:当情境提到大量同类记录且行为共享时选 OOP;提到用户界面或传感器时选事件驱动;强调固定的计算加输出流程时选过程式。
2. Data Types and Variables | 数据类型与变量
Selecting the correct data type avoids unnecessary memory use and makes operations predictable. The main types you need are integer, real/float, Boolean, character, string and sometimes date/time. A variable is a named store whose value can change while the program runs; its identifier is bound to a memory location, and its type determines which operations are legal.
选择正确的数据类型可避免不必要的内存占用,并保证操作可预测。你需要掌握的主要类型是整型、实型/浮点型、布尔型、字符型、字符串型,有时还有日期/时间型。变量是一个具名存储单元,其值在程序运行中可以改变;标识符绑定到某个内存位置,而类型决定哪些操作是合法的。
| Data type | Typical use |
|---|---|
| Integer | whole numbers such as count or age |
| Real/Float | decimal numbers such as price or temperature |
| Boolean | True/False flags |
| Character | single symbol such as 'A' |
| String | text such as "Alex" |
| Date/Time | timestamps, deadlines, durations |
For example, storing a phone number as a string avoids losing leading zeros, and storing a price as a real keeps the decimal part that an integer would discard. Conversely, storing a quantity as a string makes arithmetic impossible without casting, so choose the type that matches the operations you will perform.
例如,把电话号码存为字符串可以避免丢失开头的零;把价格存为实型可以保留整型会丢弃的小数部分。反过来,把数量存为字符串会使算术运算无法直接进行(必须先转换类型),因此应选择与将要执行的操作相匹配的类型。
Type checking matters too. A strong data type system catches errors such as adding a string to an integer at compile time, while a weak system allows the operation and may produce unexpected results. Casting (type conversion) changes one type to another, for example int(3.7) = 3 in truncation or rounding in the opposite direction.
类型检查同样重要。强类型系统能在编译阶段捕获"把字符串与整型相加"之类的错误;弱类型系统允许该操作,可能产生意外结果。类型转换(casting)把一种类型变为另一种类型,例如截断时 int(3.7) = 3,或按需向上取整。
int(3.7) = 3 | real(5) = 5.0 | str(42) = "42"
String handling is a frequent exam topic: LENGTH returns the number of characters, SUBSTRING or MID extracts part of a string, and concatenation joins two strings. Index positions are usually counted from the first character, so state your assumption if the question does not specify whether counting starts at 0 or 1.
字符串处理是高频考点:LENGTH 返回字符个数,SUBSTRING 或 MID 提取子串,连接运算把两个字符串拼接。索引位置通常从第一个字符开始计,如果题目没有说明从 0 还是从 1 开始计数,请明确写出你的假设。
3. Constants, Scope and Naming Conventions | 常量、作用域与命名规范
onstants improves readability, prevents accidental modification, and means that a change to the value needs to be made in only one place. Exam answers often award a mark simply for stating that a constant cannot be reassigned while a variable can.
常量是一旦定义就在执行期间不可更改的具名值,例如 VAT_RATE = 0.2 或 MAX_SIZE = 100。使用常量能提升可读性、防止误改,并且修改数值时只需改动一处。考试中,仅仅写出"常量不可被重新赋值,而变量可以"往往就能得分。
Scope describes where an identifier can be referenced. A local variable is declared inside a subroutine and exists only while that subroutine runs; a global variable is declared outside and is visible throughout the program. Locals reduce the chance of unintended interference and are freed when the subroutine ends, whereas globals are convenient for shared settings but make debugging harder.
作用域指标识符可以被引用的范围。局部变量在子程序内部声明,只在该子程序运行期间存在;全局变量在外部声明,在整个程序中可见。局部变量可减少意外干扰,且在子程序结束时被释放;全局变量便于共享设置,但会增加调试难度。
Good naming conventions make pseudocode readable under time pressure: use meaningful identifiers such as totalScore rather than t, use camelCase or underscores consistently, reserve uppercase for constants, and avoid reserved words. Marks are sometimes available for readable, self-documenting code, so a well-named solution can score higher than a clever but opaque one.
良好的命名规范能让你在时间压力下写出更易读的伪代码:使用有意义的标识符如 totalScore 而非 t,统一使用驼峰命名或下划线,常量用大写,避免使用保留字。评分中有时会给"可读、自解释"的代码加分,因此命名清晰的解法往往比"聪明但难懂"的解法得分更高。
4. Operators and Expressions | 运算符与表达式
lso know integer division (DIV) and modulus (MOD). DIV returns the whole-number part of a division and MOD returns the remainder, which makes them ideal for checking divisibility and for converting between units.
表达式由操作数和运算符组合而成,用于产生一个值。算术运算符是 + − × ÷,此外你还必须掌握整除(DIV)和取模(MOD)。DIV 返回商的整数部分,MOD 返回余数,因此它们非常适合判断整除性和进行单位换算。
17 DIV 5 = 3 | 17 MOD 5 = 2 | n MOD 2 = 0 means n is even
ical operators combine Booleans: AND is true only if both operands are true, OR is true if at least one is true, and NOT reverses a Boolean. De Morgan' are useful for simplifying conditions: NOT (A AND B) is equivalent to (NOT A) OR (NOT B).
关系运算符比较数值并产生布尔值:=(等于)、≠(不等于)、<、≤、>、≥。逻辑运算符用于组合布尔值:AND 在两个操作数都为真时才为真,OR 在至少一个为真时为真,NOT 反转布尔值。德摩根定律可用于化简条件:NOT (A AND B) 等价于 (NOT A) OR (NOT B)。
elational operators, then AND, and finally OR. Adding brackets to a complex condition costs nothing and removes all ambiguity, which is exactly what a marker wants to see.
运算符优先级决定求值顺序:先括号,再 NOT,然后 × ÷ DIV MOD,接着 + −,再比较运算,然后是 AND,最后 OR。给复杂条件加括号没有任何代价,却能消除歧义,这正是阅卷老师希望看到的写法。
| Priority | Operators | Example |
|---|---|---|
| 1 | ( ) | (2 + 3) × 4 = 20 |
| 2 | NOT | NOT FALSE = TRUE |
| 3 | × ÷ DIV MOD | 12 MOD 5 × 2 = 4 |
| 4 | + − | 3 + 4 × 2 = 11 |
| 5 | < ≤ > ≥ = ≠ | 5 > 3 = TRUE |
| 6 | AND then OR | TRUE AND FALSE OR TRUE = TRUE |
5. Selection: Controlling the Flow | 选择结构:控制流程
Selection allows a program to take different paths depending on a condition. The basic form is IF ... THEN ... ELSE ... ENDIF, and exam marks are usually awarded for correct comparison operators, correct use of ELSE, and closing the block with ENDIF or equivalent indentation. Forgetting to close a block is one of the most common lost marks.
选择结构让程序根据条件走不同分支。基本形式是 IF ... THEN ... ELSE ... ENDIF;得分点通常包括比较运算符是否正确、是否正确使用 ELSE、以及是否用 ENDIF(或等价缩进)结束语句块。忘记结束语句块是最常见的失分原因之一。
IF score ≥ 80 THEN grade ← "A" ELSE IF score ≥ 70 THEN grade ← "B" ELSE grade ← "C" ENDIF ENDIF
Notice that the second condition does not need to re-test score < 80, because that case has already been handled by the first branch. Writing the conditions in a sensible order avoids contradictory logic and shows the examiner that you understand flow of control rather than just pattern matching.
注意第二个条件不需要再判断 score < 80,因为该情况已被第一个分支处理。以合理的顺序书写条件可以避免逻辑矛盾,也能向考官展示你理解的是控制流程,而不只是机械套用格式。
Nested selection places an IF inside another IF, which is useful when two decisions depend on each other, for example checking membership before checking the discount level. A CASE (or SWITCH) statement is clearer when one variable is compared against several fixed values: it avoids a long chain of ELSE IF and makes the branches visually obvious.
嵌套选择是把一个 IF 放在另一个 IF 内部,适用于两个判断相互依赖的情形,例如先判断是否为会员,再判断折扣等级。当同一个变量要与多个固定值比较时,CASE(或 SWITCH)语句更清晰:它避免了冗长的 ELSE IF 链,使各分支一目了然。
, and using overlapping conditions that make one branch unreachable. If a decision involves a range, always check the boundary values, such as exactly 70 and exactly 80, because that is where markers look first.
要避免两个经典错误:在应作比较时误用单个 =(很多语言中 = 表示赋值);条件区间重叠导致某个分支永远无法执行。如果判断涉及区间,务必检验边界值,例如恰好等于 70 和恰好等于 80 的情况,因为阅卷老师最先关注的正是这些位置。
6. Iteration: Definite and Indefinite Loops | 循环结构:定次数与不定次数循环
Iteration repeats a block of code. A definite loop is used when the number of repetitions is known in advance, and is written as FOR i ← 1 TO 10 ... NEXT i. The counter is initialised, tested and incremented automatically, so a FOR loop is concise and unlikely to run forever.
循环用于重复执行一段代码。当重复次数事先已知时使用定次数循环,写作 FOR i ← 1 TO 10 ... NEXT i。计数器的初始化、条件判断和递增由循环自动完成,因此 FOR 循环简洁且几乎不会无限执行。
An indefinite loop is used when the number of repetitions depends on data, and comes in two forms. WHILE ... DO ... ENDWHILE is a pre-condition loop: the condition is tested before the body, so the body may run zero times. REPEAT ... UNTIL is a post-condition loop: the body runs at least once and the condition is tested afterwards, which suits input validation.
当重复次数取决于数据时使用不定次数循环,它有两种形式。WHILE ... DO ... ENDWHILE 是前测循环:先判断条件再执行循环体,因此循环体可能一次也不执行。REPEAT ... UNTIL 是后测循环:循环体至少执行一次,之后再判断条件,适合输入校验场景。
REPEAT INPUT age UNTIL age ≥ 0 AND age ≤ 120
This structure keeps asking until valid data arrives, which is exactly why post-condition loops are recommended for validation. A common error is combining REPEAT with a condition that is true at the start, which causes an infinite loop; always make sure something inside the body changes the value being tested.
该结构会持续请求输入,直到数据合法为止,这正是校验场景推荐使用后测循环的原因。常见错误是把 REPEAT 与一开始就为真的条件搭配,导致无限循环;务必确保循环体内有语句改变被判断的值。
loop selects the column. The total number of iterations equals outer count × inner count, so two loops of 1 to 10 give 100 iterations. If the inner loop' er variable, the outer loop breaks, so always use different counter names such as i and j.
嵌套循环是把一个循环放在另一个循环内部,这在处理二维数组时必不可少:外层循环选行,内层循环选列。总迭代次数等于外层次数 × 内层次数,因此两个 1 到 10 的循环共执行 100 次。若内层循环计数器与外层变量重名,外层循环会被破坏,因此务必使用 i、j 等不同的计数器名称。
| Loop | Test point | Minimum executions | Best used for |
|---|---|---|---|
| FOR | automatic counter | 0 (if range empty) | 广告 / Sponsored 英文原版 Oxford IB Diploma Programme IB Prepared: English B Ski… 英语 备考教辅 · 正版现货 · 学习备考通用 查看详情 / View on Taobao参考价 ¥271.0广告 / Sponsored Cambridge International AS & ALevel Mathematics Pure Mathem… 数学 备考教辅 · 正版现货 · 学习备考通用 查看详情 / View on Taobao参考价 ¥401.0更多咨询请联系16621398022(同微信) 备考资讯每日更新,关注不错过 考纲变化 · 科目分析 · 学习方法 ![]() 在微信里长按二维码识别关注 或截图后用「扫一扫 → 相册」选择本图 公众号:tutorhao |
