A-Level Edexcel Programming: Operators and Combined Expressions | 运算符与组合表达式

📚 A-Level Edexcel Programming: Operators and Combined Expressions | 运算符与组合表达式

In Edexcel A-Level Computer Science, programming questions often require you to combine arithmetic, comparison and logical operators into a single expression. This topic looks at how operators are classified, how precedence controls evaluation, and how to avoid common mistakes in pseudocode and Python.

在 Edexcel A-Level 计算机科学中,编程题经常要求你把算术、比较和逻辑运算符组合到同一个表达式中。本专题介绍运算符的分类、优先级如何控制求值顺序,以及如何在伪代码和 Python 中避免常见错误。

Operators are not isolated tools: they interact with data types, variables and Boolean logic. Understanding them clearly will help you trace code, predict output and write robust solutions in both Paper 1 and the programming project.

运算符不是孤立的工具:它们与数据类型、变量和布尔逻辑相互作用。清晰地理解运算符有助于你在 Paper 1 和编程项目中追踪代码、预测输出并写出可靠的程序。

1. Operators in the Specification | 考试大纲中的运算符

The Edexcel specification expects you to use arithmetic, relational, Boolean and assignment operators confidently. You may see them in pseudocode or in a high-level language such as Python, so you need to recognise both forms.

Edexcel 大纲要求你能够熟练使用算术、关系、布尔和赋值运算符。这些运算符可能出现在伪代码或 Python 等高级语言中,因此你需要认识两种写法。

An operator is a symbol that tells the computer to perform a specific operation on one or more operands. For example, in the expression a + b, the plus sign is the operator and a and b are the operands.

运算符是一个符号,指示计算机对一个或多个操作数执行特定操作。例如,在表达式 a + b 中,加号是运算符,a 和 b 是操作数。

Classification matters because different operator groups have different precedence, associativity and return types. A combined expression such as x + 2 > y AND z = 3 uses arithmetic, comparison and logical operators together.

分类很重要,因为不同类型的运算符具有不同的优先级、结合性和返回类型。像 x + 2 > y AND z = 3 这样的组合表达式同时使用了算术、比较和逻辑运算符。

  • Arithmetic operators: +, -, *, /, DIV, MOD, exponentiation | 算术运算符
  • Comparison operators: =, ≠, <, >, ≤, ≥ | 比较运算符
  • Logical operators: AND, OR, NOT | 逻辑运算符
  • Assignment operators: ←, =, +=, -= | 赋值运算符

2. Arithmetic Operators | 算术运算符

Arithmetic operators produce numeric results. The most common are +, -, *, /, DIV, MOD and exponentiation. In Python, / gives a float result while // gives integer floor division.

算术运算符产生数值结果。最常见的有 +、-、*、/、DIV、MOD 和幂运算。在 Python 中,/ 给出浮点数结果,而 // 给出整数向下取整除法。

Integer division and modulo are essential for problems involving digits, remainders, cycling and parity. For example, 17 DIV 5 gives 3 and 17 MOD 5 gives 2.

整数除法和取模对涉及数位、余数、循环和奇偶性的问题非常重要。例如,17 DIV 5 得到 3,17 MOD 5 得到 2。

17 DIV 5 = 3  and  17 MOD 5 = 2

Exponentiation is represented as ^ in pseudocode and ** in Python. For example, 2^3 or 2 ** 3 equals 8. This is used when calculating powers, growth or repeated multiplication.

幂运算在伪代码中写作 ^,在 Python 中写作 **。例如,2^3 或 2 ** 3 等于 8。这在计算幂、增长或重复乘法时会用到。

Unary operators such as a leading minus sign change the sign of a single operand. For example, -x + 3 means first take the negative of x, then add 3.

一元运算符如前置负号会改变单个操作数的符号。例如,-x + 3 表示先取 x 的相反数,然后加上 3。


3. Comparison and Relational Operators | 比较与关系运算符

Comparison operators compare two values and return a Boolean result: TRUE or FALSE. The main operators are =, ≠, <, >, ≤ and ≥.

比较运算符比较两个值并返回布尔结果:TRUE 或 FALSE。主要运算符有 =、≠、<、>、≤ 和 ≥。

In Python, equality is written as == while pseudocode often uses =. Inequality uses != in Python and ≠ or <> in some pseudocode styles. Mixing up = and == is a common exam error.

在 Python 中,等于写作 ==,而伪代码常用 =。不等于在 Python 中用 !=,在部分伪代码中写作 ≠ 或 <>。混淆 = 和 == 是考试中的常见错误。

Relational expressions can compare numbers, characters and sometimes strings using the underlying Unicode or ASCII ordering. For example, ‘A’ < ‘B’ is TRUE because A has a lower code point than B.

关系表达式可以比较数字、字符,有时也可以按底层 Unicode 或 ASCII 顺序比较字符串。例如,’A’ < ‘B’ 为 TRUE,因为 A 的码点低于 B。

A comparison always evaluates to one of two Boolean values. This is why it is often used inside IF, WHILE or REPEAT conditions to control program flow.

比较运算的结果总是两个布尔值之一。这就是为什么它经常用于 IF、WHILE 或 REPEAT 条件中,以控制程序的执行流程。


4. Logical Operators | 逻辑运算符

Logical operators combine Boolean values and return a Boolean result. The Edexcel pseudocode uses AND, OR and NOT, while Python uses and, or and not.

逻辑运算符组合布尔值并返回布尔结果。Edexcel 伪代码使用 AND、OR 和 NOT,Python 使用 and、or 和 not。

AND returns TRUE only when both operands are TRUE. OR returns TRUE when at least one operand is TRUE. NOT reverses a single Boolean value.

AND 仅在两个操作数都为 TRUE 时返回 TRUE。OR 在至少一个操作数为 TRUE 时返回 TRUE。NOT 反转单个布尔值。

Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading

A B A AND B A OR B NOT A
TRUE TRUE TRUE TRUE FALSE
TRUE FALSE FALSE TRUE FALSE