8.1 · Programming concepts
8.1 · 编程概念
The building blocks of a pseudocode program
伪代码程序的构建模块
This is the largest statement on the syllabus and the backbone of Paper 2: how to store data, make decisions, repeat work, break a program into parts, and keep it readable. Everything here is written in Cambridge pseudocode.
这是考纲中篇幅最大的一条陈述,也是试卷二的核心内容:如何存储数据、做出决策、重复执行工作、把程序拆分成若干部分,以及保持代码的可读性。这里的所有内容都用剑桥伪代码写成。
Explainer · 8.1.1
讲解 · 8.1.1
Variables and constants
变量与常量
A variable is a named store whose value can change while the program runs. A constant is a named store whose value is fixed when you write the program and never changes.
变量是一个具名的存储位置,其值在程序运行期间可以改变。常量是一个具名的存储位置,其值在编写程序时就已固定,永不改变。
Declare a variable with its data type: DECLARE Counter : INTEGER. Give it a value with the assignment operator: Counter ← 0.
用数据类型声明一个变量:DECLARE Counter : INTEGER。用赋值运算符给它赋值:Counter ← 0。
Declare a constant with a literal value: CONSTANT HourlyRate ← 6.50. The value must be a fixed literal written out in full, not another variable and not a calculation.
用字面值声明一个常量:CONSTANT HourlyRate ← 6.50。该值必须是完整写出的固定字面值,不能是另一个变量,也不能是一个计算式。
Identifier rules. Names use mixed case starting with a capital (NumberOfPlayers), only letters and digits, no spaces, no underscore, no accents, and never a keyword. They are treated as case-insensitive, so Total and total are the same variable. Markers regularly note a bland name like Array or X where a descriptive one was expected.
标识符规则。名称使用首字母大写的大小写混合形式(NumberOfPlayers),只能包含字母和数字,不能有空格、下划线、重音符号,也不能是关键字。它们被视为大小写不敏感,所以 Total 和 total 是同一个变量。考官经常指出,在应使用描述性名称的地方,考生却使用了 Array 或 X 这样平淡的名称。
Try it yourself
动手试试
Variables & constants in Python: DECLARE X : INTEGER then X ← 5 becomes just x = 5. A constant is a plain variable written in capitals by convention.
Python 中的变量与常量:DECLARE X : INTEGER 再加 X ← 5,在 Python 中就变成了简单的 x = 5。常量按惯例只是一个用大写字母书写的普通变量。
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.2
讲解 · 8.1.2
The five basic data types
五种基本数据类型
| Type | 类型 | Holds | 存储内容 | Literal example | 字面值示例 |
|---|---|---|---|---|---|
| INTEGER | a whole number, positive or negative | 一个整数,可正可负 | 15 -3 | ||
| REAL | a number with a fractional part | 带有小数部分的数字 | 4.7 -4.0 0.0 | ||
| CHAR | exactly one character, in single quotes | 恰好一个字符,用单引号括起 | 'x' '@' | ||
| STRING | zero or more characters, in double quotes | 零个或多个字符,用双引号括起 | "Isla Chen" "" | ||
| BOOLEAN | one of two values | 两个值中的一个 | TRUE FALSE |
A REAL literal always has at least one digit each side of the point: 4.0, not 4.. Use the word string, never the programming word from other languages. Markers note candidates giving “text” or the wrong type name.
REAL 字面值的小数点两侧总是至少各有一位数字:写作 4.0,而不是 4.。要使用string这个词,不要使用来自其他编程语言的说法。考官指出,有考生给出"text"或错误的类型名称。
Try it yourself
动手试试
The five pseudocode types are just Python values. Python has no separate CHAR, a one-letter string does the job.
这五种伪代码类型在 Python 中都只是普通的值。Python 没有独立的 CHAR 类型,用一个字符长的字符串即可代替。
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.3
讲解 · 8.1.3
Input and output
输入与输出
INPUT reads a value from the user into a variable. OUTPUT displays one or more values, separated by commas.
INPUT 从用户读取一个值存入变量。OUTPUT 显示一个或多个值,用逗号分隔。
Try it yourself
动手试试
OUTPUT … becomes print(…); INPUT X becomes x = input(…). The Inputs box below supplies what the user would type.
OUTPUT … 变成 print(…);INPUT X 变成 x = input(…)。下方的"输入"框提供用户本会输入的内容。
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.4 (a) and (b)
讲解 · 8.1.4 (a) 和 (b)
Sequence and selection
顺序与选择
Sequence is the default: statements run one after another, top to bottom. Selection chooses which statements run, using IF or CASE.
顺序是默认结构:各语句自上而下依次执行。选择结构使用 IF 或 CASE 来决定哪些语句会被执行。
IF statements
IF 语句
The ELSE clause is optional. Every IF ends with ENDIF.
ELSE 子句是可选的。每一个 IF 都以 ENDIF 结束。
CASE statements
CASE 语句
CASE picks one branch from several, based on the value of one variable. Cases are tested in order; the first match runs and the rest are skipped. OTHERWISE, if used, must be last.
CASE 根据一个变量的值,从多个分支中选出一个。各分支按顺序测试;第一个匹配的分支会被执行,其余的被跳过。若使用 OTHERWISE,它必须放在最后。
Try it yourself
动手试试
IF … THEN … ELSE … ENDIF becomes if / elif / else. Change score and re-run.
IF … THEN … ELSE … ENDIF 变成 if / elif / else。修改 score 后重新运行。
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.4 (c)
讲解 · 8.1.4 (c)
The three loop types
三种循环类型
Iteration repeats a block of statements. The syllabus uses three loops, and markers report that candidates lose marks by describing them in a way that could fit any of the three. Learn the one feature that separates each.
迭代会重复执行一段语句。考纲使用三种循环,考官报告称,考生常因描述方式可套用于任意一种循环而失分。要牢记区分每一种循环的那个独特特征。
| Loop | 循环 | Pseudocode | 伪代码 | The feature that defines it | 定义性特征 |
|---|---|---|---|---|---|
| Count-controlled FOR |
计数控制 FOR |
FOR i ← 1 TO 10 ... NEXT i |
Runs a fixed number of times, known before the loop starts. Use when you know how many repeats you need. | 运行固定次数,该次数在循环开始前就已知。当你知道需要重复多少次时使用它。 | |
| Pre-condition WHILE |
前测 WHILE |
WHILE Count < 10 DO ... ENDWHILE |
Condition tested before the block, so the block may run zero times. Use when the repeats depend on a condition that might already be false. | 条件在循环体之前测试,所以循环体可能运行零次。当重复次数取决于一个可能一开始就不成立的条件时使用它。 | |
| Post-condition REPEAT |
后测 REPEAT |
REPEAT ... UNTIL Answer = "Y" |
Condition tested after the block, so the block always runs at least once. Use when the work must happen before the check makes sense (asking for input, then validating it). | 条件在循环体之后测试,所以循环体总是至少运行一次。当必须先完成某项工作,检查才有意义时使用它(例如先要求输入,再验证)。 |
Markers report IF given as a loop answer (it is selection, not iteration), and FOR called “a statement to count”. Also: to describe how a loop was used, do not just quote the pseudocode. Say what it does, for example “a REPEAT loop re-asks for the value until the input is between 2 and 144”.
考官报告称,有考生把 IF 当作循环的答案(它是选择结构,不是迭代结构),也有人把 FOR 称为"一种用来计数的语句"。另外:要描述某个循环是如何被使用的,不要只是照抄伪代码。要说明它做了什么,例如"一个 REPEAT 循环反复要求输入数值,直到输入的数值在 2 到 144 之间"。
Try it yourself
动手试试
FOR i ← 1 TO 5 becomes for i in range(1, 6). WHILE … ENDWHILE becomes while …. Python has no REPEAT … UNTIL, the stand-in is while True with break.
FOR i ← 1 TO 5 变成 for i in range(1, 6)。WHILE … ENDWHILE 变成 while …。Python 没有 REPEAT … UNTIL,替代方案是配合 break 使用的 while True。
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Step through
逐步演示
Tracing a WHILE loop
追踪一个 WHILE 循环
This loop adds the numbers 1 to 5. Click through and watch the condition being tested each time, and the two variables change.
这个循环将数字 1 到 5 相加。逐步点击,观察每一次条件测试,以及两个变量的变化。
Explainer · 8.1.4 (d)
讲解 · 8.1.4 (d)
Totalling and counting
累加与计数
Totalling keeps a running sum: Total ← Total + Value. Counting keeps a running tally: Count ← Count + 1. Both need to be set to 0 before the loop, or the first addition works on an undefined value.
累加保持一个不断累积的总和:Total ← Total + Value。计数保持一个不断累积的计数:Count ← Count + 1。两者都需要在循环之前设为 0,否则第一次相加将作用于一个未定义的值。
Try it yourself
动手试试
Totalling and counting: set both to 0 before the loop, then add inside it.
累加与计数:在循环之前把两者都设为 0,然后在循环内部进行累加。
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.4 (e)
String handling
Four string routines are on the syllabus. In each, the string is given first.
| Routine | Returns | Example |
|---|---|---|
| LENGTH(s) | the number of characters | LENGTH("Bright Star") → 11 |
| SUBSTRING(s, start, len) | a piece of the string, len characters long, from position start | SUBSTRING("Bright Star", 1, 6) → "Bright" |
| UCASE(s) | the string in upper case | UCASE("Bright") → "BRIGHT" |
| LCASE(s) | the string in lower case | LCASE('K') → 'k' |
The first character can be position 0 or 1 depending on the question, so read the numbering the question gives you. The syllabus examples number from 1. A question using SUBSTRING usually states its exact syntax; use it as given.
Name ← "Isla Chen" (positions numbered from 1)
Try it yourself
LENGTH becomes len(), SUBSTRING becomes slicing, UCASE/LCASE become .upper()/.lower(). Python slices count from 0.
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.4 (f)
Operators
Arithmetic
+ - * / and ^ (raise to a power). * and / bind tighter than + and -; use brackets to be sure. Integer division uses two routines:
Markers report MOD being confused with subtraction, and candidates unsure which operator type DIV belongs to (it is arithmetic).
Relational
= < <= > >= <> (not equal). The result is always BOOLEAN.
Logical
AND, OR, NOT only. Operands and results are BOOLEAN. In IF Grade = 'A' OR Grade = 'B' the branch runs when either comparison is true.
Try it yourself
Arithmetic maps across directly. DIV(a, b) is a // b, MOD(a, b) is a % b, and ^ is **.
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.5
Nested statements
A statement inside another statement is nested. Selection can nest inside iteration, iteration inside selection, and so on. Cambridge will not ask for more than three levels deep. Indent each level to show it clearly.
Try it yourself
Nesting is shown by indentation. This is a loop, containing a selection, containing another selection: three levels.
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.6
Procedures and functions
Both group a block of code under a name so it can be reused. The difference: a function returns a value and is used inside an expression; a procedure does not return a value and is run as its own statement with CALL.
Procedure
Function
Markers report the keyword CALL wrongly put in front of a function call, missing data types on the parameters or on RETURNS, and candidates writing the header when asked to write the call. A procedure or function may have up to three parameters.
Local and global variables
A local variable is declared inside a procedure or function and exists only while that routine runs. A global variable is declared in the main program and can be used anywhere. Prefer local variables and parameters: they keep each routine self-contained and easier to maintain.
Try it yourself
A PROCEDURE becomes a def that just acts. A FUNCTION becomes a def with return, used inside an expression, with no CALL in front.
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.7
Library routines
| Routine | Does | Example |
|---|---|---|
| DIV(a, b) | whole-number part of a ÷ b | DIV(17, 5) → 3 |
| MOD(a, b) | remainder of a ÷ b | MOD(17, 5) → 2 |
| ROUND(x, places) | x rounded to places decimal places | ROUND(4.7354, 2) → 4.74 |
| RANDOM() | a random decimal from 0 up to 1 | ROUND(RANDOM() * 6, 0) → a whole 0 to 6 |
Markers report candidates unsure of the purpose of DIV, MOD and ROUND, and reaching for INT (not a 0478 routine) instead.
Try it yourself
DIV, MOD and ROUND in action. (RANDOM() needs an import, so it is not shown here.)
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Explainer · 8.1.8
Writing a maintainable program
A maintainable program can be understood and changed later by another programmer. Markers award marks for naming, and explaining, techniques like these:
Meaningful identifiers for variables, constants, procedures and functions, so the code reads for itself.
Comments (//) explaining what a section does and why, not restating the obvious.
Procedures and functions that split the program into named, single-purpose parts, each testable and reusable on its own.
Consistent indentation and white space so the structure is visible at a glance.
When a question asks for the maintenance benefit of procedures and functions specifically, the point is that a change to one task is made in one place, and each part can be tested separately, rather than that they save typing.
Try it yourself
Both halves compute the same thing. Run it: the two outputs are identical, but which version would you rather come back to in six months?
Running in the offline fallback engine. The full Python engine could not load (blocked network, or no internet), so this console switched to a small hand-written one. It runs the core of Python: variables, if/elif/else, for and while loops, input(), functions, and string handling. It is not full Python.
正在使用离线备用引擎运行。完整的 Python 引擎未能加载(网络被屏蔽,或没有网络连接),因此本控制台切换到了一个小型的手写引擎。它支持 Python 的核心部分:变量、if/elif/else、for 和 while 循环、input()、函数,以及字符串处理。它并非完整的 Python。
Check your understanding
检验你的理解
A program asks the user for a value, then keeps asking again until the value entered is valid. Which loop type fits?
某程序要求用户输入一个数值,然后不断重新要求输入,直到输入的数值有效为止。哪种循环类型合适?
Check your understanding
检验你的理解
AreaOfCircle is a function that returns a REAL. Which line uses it correctly?
AreaOfCircle 是一个返回 REAL 类型的函数。以下哪一行正确地使用了它?
Check your understanding
检验你的理解
What is the value of DIV(23, 4)?
DIV(23, 4) 的值是多少?
Common mistakes
常见错误
8.1.4 / 8.1.6 / 8.1.7
考官针对 8.1.4 / 8.1.6 / 8.1.7 报告了以下模式
RecurringOn loops, markers reported descriptions that could fit any of the three types, and IF given as a loop answer. Name the distinguishing feature: FOR is a fixed count, WHILE tests first and may run zero times, REPEAT runs at least once and tests at the end.
反复出现在循环方面,考官报告称描述套用于三种类型中的任何一种都成立,还有考生把 IF 当作循环的答案。要点出区分特征:FOR 是固定次数,WHILE 先测试且可能运行零次,REPEAT 至少运行一次且在最后测试。
On functions, the keyword CALL is wrongly used for a function (it is procedures only), and data types are left off the parameters or the RETURNS type. When asked for the call, some candidates write the header instead.
在函数方面,关键字 CALL 被错误地用于函数(它只用于过程),而且参数或 RETURNS 类型上遗漏了数据类型。被要求写出调用语句时,部分考生反而写出了函数头。
On operators, MOD is treated as subtraction, and DIV is not recognised as an arithmetic operator. Candidates also reach for INT, which is not part of the 0478 pseudocode.
在运算符方面,MOD 被当成了减法,而 DIV 未被识别为算术运算符。部分考生还会用到 INT,但它并不属于 0478 伪代码。
CALL on a function: CALL AreaOfCircle(5.0), or a function header with no return type: FUNCTION AreaOfCircle(R).
对函数使用 CALL: CALL AreaOfCircle(5.0),或函数头没有返回类型:FUNCTION AreaOfCircle(R)。
Function in an expression, types on everything: FUNCTION AreaOfCircle(R : REAL) RETURNS REAL, then Area ← AreaOfCircle(5.0).
函数用在表达式中,每处都标明类型: FUNCTION AreaOfCircle(R : REAL) RETURNS REAL,然后 Area ← AreaOfCircle(5.0)。
Loop description that fits anything: “a loop was used to repeat the code”.
套用于任何情况的循环描述:"使用了一个循环来重复代码。"
Names the feature: “a WHILE loop, tested before each pass, so it stops as soon as Count reaches 10 and runs the body 9 times”.
点出具体特征:"一个 WHILE 循环,每次运行前都会测试,所以一旦 Count 达到 10 就会停止,循环体共运行 9 次。"
Go deeper
深入练习
Ready to put it all together?
准备好把这些知识整合起来了吗?
The 15-mark scenario question combines almost everything here: variables and arrays, a loop with a nested check, totalling, validation, and often a procedure. The full worked remediation is already built.
15 分情境题几乎结合了这里的所有内容:变量与数组、带有嵌套检查的循环、累加、验证,通常还会有一个过程。完整的详解补救练习已经准备就绪。
Revision questions
复习题
Past-paper style. Write an answer, then reveal the marking points and mark yourself.
采用历年真题风格。写下答案,然后展开评分要点给自己打分。
[2]State one difference between a variable and a constant, and give a suitable use for a constant.
[2]陈述变量与常量之间的一个区别,并给出常量的一个恰当用途。
Marking points
评分要点
- Difference: a variable's value can change while the program runs; a constant's value is fixed when the program is written and cannot change.
- Suitable use for a constant: a value that never changes but is used in many places, e.g. an hourly pay rate, VAT rate, Pi, or a maximum number of players.
- 区别:变量的值可以在程序运行时改变;常量的值在编写程序时就固定,不能改变。
- 常量的恰当用途:一个从不改变但在许多地方用到的值,例如时薪、增值税率、圆周率,或最大玩家数。
[4]Name two of the three loop types and, for each, give one feature that distinguishes it from the others.
[4]说出三种循环类型中的两种,并针对每一种给出一个将其与其他类型区分开来的特征。
Marking points
评分要点
- Name two of: FOR, WHILE, REPEAT (UNTIL).
- FOR: repeats a fixed, known number of times.
- WHILE: tests the condition before each pass, so it may run zero times.
- REPEAT UNTIL: tests the condition after each pass, so the body always runs at least once.
- 从以下三种中任选两种:FOR、WHILE、REPEAT (UNTIL)。
- FOR:重复固定的、已知的次数。
- WHILE:在每次循环之前测试条件,所以可能一次都不运行。
- REPEAT UNTIL:在每次循环之后测试条件,所以循环体总是至少运行一次。
[3]Write pseudocode for a function Bigger that takes two INTEGER parameters and returns the larger of the two.
[3]为函数 Bigger 编写伪代码,该函数接收两个 INTEGER 参数,并返回其中较大的一个。
Marking points
评分要点
- FUNCTION header with typed parameters and a RETURNS type: FUNCTION Bigger(A : INTEGER, B : INTEGER) RETURNS INTEGER
- Selection to compare: IF A > B THEN RETURN A ELSE RETURN B ENDIF
- ENDFUNCTION
- Marks for: correct header with types, correct comparison, correct RETURN of the larger value.
- 带类型参数和 RETURNS 类型的 FUNCTION 头:FUNCTION Bigger(A : INTEGER, B : INTEGER) RETURNS INTEGER
- 用选择来比较:IF A > B THEN RETURN A ELSE RETURN B ENDIF
- ENDFUNCTION
- 评分点:带类型的正确头部、正确的比较、正确 RETURN 较大的值。
[2]State the value of MOD(30, 7) and of DIV(30, 7).
[2]陈述 MOD(30, 7) 和 DIV(30, 7) 的值。
Marking points
评分要点
- MOD(30, 7) = 2 (the remainder of 30 divided by 7).
- DIV(30, 7) = 4 (the whole-number part of 30 divided by 7).
- MOD(30, 7) = 2(30 除以 7 的余数)。
- DIV(30, 7) = 4(30 除以 7 的整数部分)。
[4]Describe two techniques a programmer can use to make a program easier to maintain.
[4]描述程序员可用来使程序更易维护的两种技巧。
Marking points
评分要点
- Any two of: meaningful identifiers (names that say what they hold); comments explaining non-obvious code; splitting the program into procedures and functions; consistent indentation and white space.
- For each, one line on why it helps maintenance (easier to read, find and change code).
- 以下任选两项:有意义的标识符(名字说明它保存什么);解释不明显代码的注释;把程序拆分为过程和函数;一致的缩进和空白。
- 每一项写一句为什么有助于维护(更易阅读、查找和修改代码)。
Flashcards
记忆卡片
Active recall for this subtopic’s key terms.
针对本子主题关键术语的主动回忆练习。
Keep this subtopic’s practice with you
把这个子主题的练习保存下来
Free account: save your progress and unlock every revision question for 8.1, and every other IGCSE 0478 statement.
免费账户:解锁 8.1 以及所有其他 IGCSE 0478 考纲陈述的每一道复习题,并同步你的学习进度。