Tag: 编程

  • Object-Oriented Programming for Edexcel A-Level Computer Science | 爱德思 A-Level 计算机科学:面向对象编程

    📚 Object-Oriented Programming for Edexcel A-Level Computer Science | 爱德思 A-Level 计算机科学:面向对象编程

    Object-oriented programming (OOP) is a fundamental programming paradigm covered in the Edexcel A-Level Computer Science specification. It models real-world entities as objects that contain both data and behaviour, making code more modular, reusable and easier to maintain. This revision guide covers the key OOP concepts you need to master for the exam, including classes, objects, inheritance, polymorphism, encapsulation and design relationships.

    面向对象编程(OOP)是爱德思 A-Level 计算机科学考试大纲中的一个基本编程范式。它将现实世界中的实体建模为同时包含数据和行为的对象,使代码更模块化、可复用且更易维护。本复习指南涵盖考试中需要掌握的关键 OOP 概念,包括类、对象、继承、多态、封装和设计关系。


    1. What is Object-Oriented Programming? | 什么是面向对象编程?

    OOP is a programming paradigm based on the concept of objects, which combine data (attributes) and behaviour (methods). Unlike procedural programming, which separates code from data, OOP organises software design around objects that represent real-world entities. This approach improves modularity, reusability and maintainability. Edexcel A-Level focuses on classes, objects, inheritance, polymorphism and encapsulation.

    面向对象编程(OOP)是一种基于对象的编程范式,对象将数据(属性)和行为(方法)结合在一起。与将代码和数据分离的面向过程编程不同,OOP 围绕代表现实世界实体的对象来组织软件设计。这种方法提高了模块化、可重用性和可维护性。爱德思 A-Level 重点关注类、对象、继承、多态和封装。


    2. Classes and Objects | 类和对象

    A class is a blueprint or template for creating objects. It defines the attributes and methods that objects of that class will have. An object is an instance of a class, created at runtime. For example, a Car class might define attributes such as colour and speed, and methods such as accelerate() and brake(); a specific object would be a red car with speed 60 km/h.

    类是创建对象的蓝图或模板,它定义了该类的对象将具有的属性和方法。对象是类在运行时创建的实例。例如,Car 类可以定义颜色和速度等属性,以及 accelerate() 和 brake() 等方法;一个具体的对象可能是一辆速度为 60 km/h 的红色汽车。


    3. Attributes and Methods | 属性和方法

    Attributes store the state of an object. They can be instance variables, which belong to each individual object, or class variables, which are shared across all instances. Methods define the behaviour of an object. In Edexcel exams, you may need to identify public and private attributes and explain why private attributes protect data integrity.

    属性存储对象的状态。属性可以是属于每个单独对象的实例变量,也可以是在所有实例之间共享的类变量。方法定义对象的行为。在爱德思考试中,你可能需要识别公有和私有属性,并解释为什么私有属性可以保护数据完整性。


    4. Encapsulation and Access Modifiers | 封装与访问修饰符

    Encapsulation means bundling data and methods inside a class and restricting direct access to the internal state. In Python, privacy is indicated by a single underscore convention, while languages like Java use private keyword. Access to private attributes is provided through getter and setter methods. Encapsulation reduces unintended interference and helps maintain invariants.

    封装意味着将数据和方法捆绑在类内部,并限制对内部状态的直接访问。在 Python 中,私有性通过单下划线约定来表示,而 Java 等语言使用 private 关键字。对私有属性的访问通过 getter 和 setter 方法提供。封装减少了意外干扰,有助于维护不变量。


    5. Inheritance and Class Hierarchies | 继承与类层次结构

    Inheritance allows a class (subclass) to derive properties and methods from another class (superclass). This supports code reuse and hierarchical classification. For example, Dog and Cat can inherit from Animal, gaining common features such as eat() and sleep(), while adding specific behaviours like bark() or purr(). Edexcel exams often ask about superclasses, subclasses and overriding.

    继承允许一个类(子类)从另一个类(超类)派生属性和方法。这支持代码重用和层次分类。例如,Dog 和 Cat 可以从 Animal 继承,获得 eat() 和 sleep() 等共同特征,同时增加 bark() 或 purr() 等特定行为。爱德思考试经常考查超类、子类和方法重写。


    6. Polymorphism and Method Overriding | 多态与方法重写

    Polymorphism means ‘many forms’. It allows objects of different subclasses to be treated as objects of a common superclass, but the actual method executed is determined at runtime based on the object type. Method overriding is a key mechanism: a subclass provides its own implementation of a method already defined in the superclass. This enables flexible and extensible code.

    多态意味着“多种形态”。它允许不同子类的对象被视为公共超类的对象,但实际执行的方法在运行时根据对象类型确定。方法重写是一个关键机制:子类提供自己的实现,替代超类中已定义的方法。这使得代码灵活且可扩展。


    7. Constructors and Destructors | 构造函数与析构函数

    A constructor is a special method that initialises a new object. In Python, __init__ is called automatically when an object is created. It sets the initial state of the object and can accept parameters. A destructor, such as __del__ in Python, is rarely needed because Python has automatic garbage collection. Exam questions may ask you to write or trace constructor code.

    构造函数是一种特殊方法,用于初始化新对象。在 Python 中,__init__ 在创建对象时自动调用。它设置对象的初始状态并可以接受参数。析构函数(如 Python 中的 __del__)很少需要,因为 Python 具有自动垃圾回收机制。考试题可能要求编写或跟踪构造函数代码。


    8. Association, Aggregation and Composition | 关联、聚合与组合

    These terms describe relationships between classes. Association is a generic ‘uses a’ relationship. Aggregation is a ‘has a’ relationship where the contained object can exist independently, e.g. a Department has Employees. Composition is a stronger ‘has a’ relationship where the part cannot exist without the whole, e.g. a House has Rooms. Recognising these relationships helps design class diagrams.

    这些术语描述类之间的关系。关联是一种通用的“使用”关系。聚合是一种“拥有”关系,被包含的对象可以独立存在,例如 Department 拥有 Employees。组合是一种更强的“拥有”关系,部分不能脱离整体而存在,例如 House 拥有 Rooms。识别这些关系有助于设计类图。


    9. Static and Class Members | 静态成员与类成员

    Static members belong to the class rather than any instance. In Python, class variables and @staticmethod / @classmethod decorators provide this functionality. They are useful for constants, utility functions, and counting instances. In Edexcel exams, static vs instance members may appear in multiple-choice or short-answer questions.

    静态成员属于类本身,而不是任何实例。在 Python 中,类变量以及 @staticmethod / @classmethod 装饰器提供了这种功能。它们常用于常量、工具函数和实例计数。在爱德思考试中,静态成员与实例成员的区别可能出现在选择题或简答题中。


    10. SOLID Design Principles Overview | SOLID 设计原则概述

    SOLID is a set of five design principles that improve OOP code quality: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation and Dependency Inversion. While A-Level does not require deep implementation, understanding these principles helps answer high-band questions on maintainability, extensibility and code reuse.

    SOLID 是改善 OOP 代码质量的五项设计原则:单一职责、开闭原则、里氏替换、接口隔离和依赖倒置。虽然 A-Level 不要求深入实现,但理解这些原则有助于回答关于可维护性、可扩展性和代码复用性的高分题。


    11. Practical Example – Bank Account System | 实例分析——银行账户系统

    Consider a BankAccount class with private attribute balance, methods deposit(amount) and withdraw(amount), and a subclass SavingsAccount that overrides withdraw to enforce a minimum balance. This example demonstrates encapsulation, inheritance and polymorphism in one small system. Students should be able to identify class relationships and trace method calls.

    考虑一个 BankAccount 类,具有私有属性 balance、方法 deposit(amount) 和 withdraw(amount),以及一个子类 SavingsAccount,它重写 withdraw 以强制最低余额。这个例子在一个小系统中展示了封装、继承和多态。学生应能够识别类关系并跟踪方法调用。


    12. Exam Tips and Common Pitfalls | 考试技巧与常见错误

    In Edexcel exams, always use correct terminology: class, object, instance, attribute, method, encapsulation, inheritance, polymorphism. Avoid vague words like ‘thing’ or ‘function’. When explaining advantages, link to maintainability, reusability, security and modularity.

    在爱德思考试中,务必使用正确的术语:类、对象、实例、属性、方法、封装、继承、多态。避免使用“东西”或“功能”等模糊词语。在解释优点时,要联系可维护性、可重用性、安全性和模块化。

    Common pitfalls to avoid:

    • confusing classes with objects
    • forgetting to mention private access when describing encapsulation
    • using inheritance where composition would be more appropriate

    需要避免的常见错误:

    • 混淆类和对象
    • 描述封装时忘记提及私有访问
    • 在应该使用组合时错误地使用了继承

    Published by TutorHao | Computer Science Revision Series | aleveler.com

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

  • Object-Oriented Programming for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学面向对象编程精讲

    📚 Object-Oriented Programming for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学面向对象编程精讲

    Object-oriented programming (OOP) is a key topic in the Edexcel A-Level Computer Science specification. It moves beyond procedural thinking by grouping data and behaviour into reusable classes. This article explains the concepts, pseudocode patterns and Python examples you need for exam success.

    面向对象编程(OOP)是 Edexcel A-Level 计算机科学考试大纲中的核心主题。它超越面向过程的思维,将数据和行为封装在可复用的类中。本文讲解你考试成功所需的概念、伪代码模式和 Python 示例。


    1. Why OOP Matters in Edexcel A-Level Programming | 为什么面向对象编程在 Edexcel A-Level 编程中重要

    Edexcel A-Level Computer Science asks you to design, trace and evaluate programs using both procedural and object-oriented techniques. OOP questions often require you to identify classes, state their attributes and methods, and suggest improvements using inheritance or encapsulation.

    Edexcel A-Level 计算机科学要求你使用面向过程和面向对象技术来设计、追踪和评估程序。OOP 题目通常要求你识别类,列出其属性和方法,并建议使用继承或封装进行改进。

    Understanding OOP is not just about writing code. It helps you model real-world problems in a way that is modular, maintainable and exam-friendly. Examiners reward clear class diagrams and concise explanations of how objects interact.

    理解 OOP 不仅仅是编写代码。它帮助你以模块化、可维护且适合考试的方式对现实世界问题进行建模。考官欣赏清晰的类图以及对对象之间如何交互的简洁解释。


    2. Classes and Objects: The Core Building Blocks | 类与对象:核心构建块

    A class is a blueprint or template that defines the attributes (data) and methods (behaviour) of a group of similar objects. An object is a specific instance of a class, created at runtime with its own state.

    类是定义一组相似对象的属性(数据)和方法(行为)的蓝图或模板。对象是类的一个具体实例,在运行时被创建并拥有自己的状态。

    For example, a class called Car might define attributes such as colour and speed, and methods such as accelerate() and brake(). Each Car object can have different values for those attributes.

    例如,一个名为 Car 的类可以定义属性如 colourspeed,以及方法如 accelerate()brake()。每个 Car 对象可以为这些属性拥有不同的值。


    3. Attributes, Methods and Constructors | 属性、方法与构造器

    Attributes store the state of an object. In Python, attributes are usually initialised inside a constructor method called __init__. In pseudocode, Edexcel often uses a CLASSENDCLASS structure with a constructor like PROCEDURE NEW.

    属性存储对象的状态。在 Python 中,属性通常在名为 __init__ 的构造方法内初始化。在伪代码中,Edexcel 通常使用 CLASSENDCLASS 结构,并使用类似 PROCEDURE NEW 的构造器。

    Methods define what an object can do. A method is simply a function that belongs to a class. Constructor methods run automatically when an object is instantiated, setting up initial values such as default speed or empty lists.

    方法定义对象可以做什么。方法就是属于类的函数。构造方法在对象实例化时自动运行,设置初始值,例如默认速度或空列表。

    class Car: __init__(self, c, s): self.colour = c; self.speed = s


    4. Encapsulation and Access Modifiers | 封装与访问修饰符

    Encapsulation means keeping an object’s internal data private and exposing only the necessary methods to the outside world. This prevents invalid states and reduces coupling between parts of a program.

    封装意味着将对象的内部数据保持为私有,只向外部暴露必要的方法。这可以防止无效状态并降低程序各部分之间的耦合。

    In Python, a single underscore prefix such as _speed indicates that an attribute is intended to be protected. In Edexcel pseudocode, you may see PRIVATE and PUBLIC keywords. Getter and setter methods are used to read and modify private attributes safely.

    在 Python 中,单下划线前缀如 _speed 表示该属性应被视为受保护。在 Edexcel 伪代码中,你可能会看到 PRIVATEPUBLIC 关键字。Getter 和 setter 方法用于安全地读取和修改私有属性。


    5. Inheritance: Extending Behaviour | 继承:扩展行为

    Inheritance allows a new class to acquire the attributes and methods of an existing class. The new class is called a subclass or derived class, while the existing class is the superclass or base class.

    继承允许新类获取现有类的属性和方法。新类称为子类或派生类,而现有类是超类或基类。

    Inheritance supports code reuse and represents an ‘is a’ relationship. For example, an ElectricCar class can inherit from Car and add a batteryCapacity attribute and a charge() method.

    继承支持代码复用,并表示 ‘is a’ 关系。例如,ElectricCar 类可以继承 Car,并添加 batteryCapacity 属性和 charge() 方法。

    class ElectricCar(Car): __init__(self, c, s, b): super().__init__(c, s); self.battery = b


    6. Polymorphism: Many Forms of a Method | 多态:方法的多态性

    Polymorphism allows methods with the same name to behave differently depending on the object that calls them. This is often achieved through method overriding, where a subclass provides its own implementation of a superclass method.

    多态允许同名方法根据调用它的对象而表现出不同的行为。这通常通过方法重写实现,即子类提供自己对超类方法的实现。

    For example, a Vehicle class may define a move() method. A Car subclass might override move() to print ‘driving on road’, while a Boat subclass prints ‘sailing on water’.

    例如,Vehicle 类可以定义 move() 方法。Car 子类可以重写 move() 以输出 ‘driving on road’,而 Boat 子类输出 ‘sailing on water’。

    Polymorphism is a common exam focus because it tests whether you understand dynamic method dispatch and how the same interface can hide different underlying behaviours.

    多态是常见的考试重点,因为它考查你是否理解动态方法分派,以及同一接口如何隐藏不同的底层行为。


    7. Association, Aggregation and Composition | 关联、聚合与组合

    Objects do not exist in isolation. Association describes any relationship where one object uses or interacts

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

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

  • Edexcel A-Level Programming: From Core Constructs to Algorithm Design | Edexcel A-Level 编程:从核心结构到算法设计

    📚 Edexcel A-Level Programming: From Core Constructs to Algorithm Design | Edexcel A-Level 编程:从核心结构到算法设计

    Programming is at the heart of the Edexcel A-Level Computer Science specification. Candidates must be able to trace, write and evaluate code in a high-level language, applying core constructs to solve problems efficiently. This revision guide covers the essential programming techniques, data structures and algorithms you need for both Paper 1 and the practical programming project.

    编程是 Edexcel A-Level 计算机科学考试的核心。考生必须能够跟踪、编写和评估高级语言代码,运用核心结构高效地解决问题。本复习指南涵盖 Paper 1 和编程实践项目所需的基本编程技术、数据结构和算法。

    1. Sequence, Selection and Iteration | 顺序、选择与迭代

    The three fundamental control structures are sequence, selection and iteration. Sequence executes statements in written order; selection uses if, else if and switch-case statements; iteration repeats blocks with for, while and do-while loops. Every program can be built from these three building blocks.

    三种基本控制结构是顺序、选择和迭代。顺序按书写顺序执行语句;选择使用 if、else if 和 switch-case 语句;迭代使用 for、while 和 do-while 循环重复代码块。每个程序都可以由这三个基本构件组成。

    Edexcel questions often ask you to convert a flowchart or pseudocode into a working program. You must be confident with nested conditions and loop counters, including off-by-one errors. For example, a loop that should run 10 times but uses counter < 10 will stop after 10 iterations, while counter <= 10 will run 11 times.

    Edexcel 考题经常要求你将流程图或伪代码转换为可运行的程序。你必须熟练掌握嵌套条件和循环计数器,包括差一错误(off-by-one errors)。例如,一个应该运行 10 次的循环使用 counter < 10 会在 10 次迭代后停止,而使用 counter <= 10 会运行 11 次。

    When tracing nested loops, pay attention to the order in which variables update. The inner loop completes all its iterations for each pass of the outer loop. Questions may ask you to state the final value of a variable or the number of times a print statement executes.

    跟踪嵌套循环时,要注意变量更新的顺序。内层循环在外层循环的每一遍中完成它的所有迭代。题目可能要求你写出变量的最终值或打印语句执行的次数。


    2. Data Types and Variables | 数据类型与变量

    Variables must be declared with an appropriate data type: integer, real/float, Boolean, character and string. Strong typing helps prevent invalid operations and makes code more readable. Choosing the correct type also affects memory usage and arithmetic behaviour.

    变量必须以合适的数据类型声明:整型、实型/浮点型、布尔型、字符型和字符串型。强类型有助于防止无效操作,并使代码更易读。选择正确的类型还会影响内存使用和算术行为。

    Type coercion and casting are common pitfalls. For example, dividing two integers in some languages truncates the result, while casting to float preserves the decimal part. You should know how to explicitly convert between types using functions like int(), float() and str().

    类型强制转换和显式转换是常见陷阱。例如,在某些语言中两个整数相除会截断结果,而转换为浮点型则保留小数部分。你应该知道如何使用 int()、float() 和 str() 等函数在类型之间显式转换。

    Constants are named values that do not change during program execution. They improve readability and maintainability. For instance, declaring TAX_RATE = 0.2 is clearer than using the literal 0.2 throughout the code, and it makes updates easier.

    常量是在程序执行期间不改变的有名称的值。它们提高了可读性和可维护性。例如,声明 TAX_RATE = 0.2 比在整个代码中使用字面量 0.2 更清晰,并且使更新更容易。


    3. Arrays, Lists and Records | 数组、列表与记录

    Arrays store multiple values of the same type in contiguous memory locations, accessed by an index starting at 0 or 1 depending on the language. Lists are dynamic and can grow or shrink at runtime. In pseudocode, you may see array indices written as arr[0], arr[1] and so on.

    数组在连续内存位置中存储相同类型的多个值,通过索引访问,索引从 0 或 1 开始取决于语言。列表是动态的,可以在运行时增长或缩小。在伪代码中,你可能看到数组索引写作 arr[0]、arr[1] 等。

    Records (or structs) group fields of different types under one name. A record for a student might contain a string name, an integer age and a float average mark. You can create an array of records to store data for many students, and then access fields using dot notation such as student.name.

    记录(或结构体)将不同类型的字段组合在一个名称下。一个学生的记录可能包含字符串姓名、整型年龄和浮点型平均分。你可以创建一个记录数组来存储许多学生的数据,然后使用点符号(如 student.name)访问字段。

    Two-dimensional arrays are useful for representing grids, tables and matrices. You must be able to read from and write to a cell using row and column indices, for example grid[2][3]. Trace questions often involve nested loops iterating over each row and column.

    二维数组用于表示网格、表格和矩阵。你必须能够使用行索引和列索引读取和写入单元格,例如 grid[2][3]。跟踪题通常涉及遍历每一行和每一列的嵌套循环。


    4. Functions and Procedures | 函数与过程

    Functions return a value, while procedures (or subroutines) perform a task without returning a value. Parameters can be passed by value or by reference. Using functions and procedures breaks a large problem into smaller, reusable modules.

    函数返回一个值,而过程(或子程序)执行任务但不返回值。参数可以按值传递或按引用传递。使用函数和过程将大问题分解为更小、可复用的模块。

    Passing by value copies the argument, so the original variable is unchanged. Passing by reference allows the function to modify the caller’s variable, which is useful for returning multiple results. In Edexcel pseudocode, parameters are usually passed by value unless otherwise stated.

    按值传递复制实参,因此原始变量不变。按引用传递允许函数修改调用者的变量,这在需要返回多个结果时很有用。在 Edexcel 伪代码中,参数通常按值传递,除非另有说明。

    Local variables exist only within a function or procedure and are destroyed when it returns. Global variables are accessible throughout the program but can make debugging harder. You should understand the scope of a variable and how it affects side effects and state.

    局部变量仅存在于函数或过程内部,并在返回时销毁。全局变量在整个程序中可访问,但会使调试更困难。你应该理解变量的作用域及其对副作用和状态的影响。


    5. Recursion and The Call Stack | 递归与调用栈

    Recursion is a technique where a function calls itself until a base case is reached. Classic examples include factorial n! = n × (n-1)! and Fibonacci numbers. A recursive function must have at least one base case to stop the chain of calls.

    递归是一种函数调用自身直到达到基准情形的技术。经典例子包括阶乘 n! = n × (n-1)! 和斐波那契数列。递归函数必须至少有一个基准情形来停止调用链。

    Each recursive call is placed on the call stack, storing parameters, local variables and the return address. If the base case is missing or unreachable, a stack overflow occurs. Understanding the call stack helps you trace recursive functions in exam questions.

    每个递归调用都被放入调用栈,存储参数、局部变量和返回地址。如果缺少基准情形或无法达到,就会发生栈溢出。理解调用栈有助于你在考试题中跟踪递归函数。

    Recursion can be elegant but may be less efficient than iteration because of the overhead of stack frames. Some problems, such as tree traversal, are naturally recursive, while others can be solved clearly with loops. Edexcel expects you to compare both approaches.

    递归可能很优雅,但由于栈帧的开销,可能比迭代效率低。有些问题(如树遍历)天然适合递归,而其他问题可以用循环清晰地解决。Edexcel 期望你能够比较这两种方法。

    n! = n × (n – 1)! for n > 1, with 1! = 1


    6. Searching and Sorting Algorithms | 搜索与排序算法

    Linear search checks each element in turn and works on unsorted data. Binary search repeatedly halves a sorted array, achieving O(log n) time complexity. You must be able to trace both algorithms and state the number of comparisons made.

    线性搜索依次检查每个元素,适用于未排序数据。二分搜索不断将有序数组对半分割,实现 O(log n) 时间复杂度。你必须能够跟踪这两种算法并说明比较次数。

    Common sorting algorithms include bubble sort, insertion sort and merge sort. Bubble sort compares adjacent items and swaps them if needed; merge sort divides the list and merges sorted halves. Edexcel may ask you to complete a pass of bubble sort or list the steps of a merge.

    常见排序算法包括冒泡排序、插入排序和归并排序。冒泡排序比较相邻项并在需要时交换;归并排序将列表分割后合并已排序的两半。Edexcel 可能要求你完成一趟冒泡排序或列出归并的步骤。

    Algorithm Best Average Worst Stable?
    Bubble sort O(n) O(n²) O(n²) Yes
    Insertion sort O(n) O(n²) O(n²) Yes
    Merge sort O(n log n) O(n log n) O(n log n) Yes

    mid = (low + high) ÷ 2 (integer division for binary search)


    7. Object-Oriented Programming Essentials | 面向对象编程基础

    OOP models real-world entities using classes and objects. A class is a blueprint, while an object is an instance with attributes (fields) and methods. For example, a Car class might have attributes make and speed, and methods accelerate() and brake().

    面向对象编程使用类和对象对现实世界实体建模。类是蓝图,而对象是具有属性(字段)和方法(函数)的实例。例如,Car 类可能有属性 make 和 speed,以及方法 accelerate() 和 brake()。

    Encapsulation hides internal state and exposes a public interface. Attributes are often declared private and accessed through getter and setter methods. This protects data from invalid changes and makes the class easier to maintain.

    封装隐藏内部状态并暴露公共接口。属性通常声明为私有,并通过 getter 和 setter 方法访问。这可以防止无效更改,并使类更易于维护。

    Inheritance allows a subclass to reuse and extend a superclass, while polymorphism lets different classes respond to the same method call in their own way. Edexcel questions may ask you to identify the relationship between classes in a UML diagram or code snippet.

    继承允许子类复用和扩展父类,而多态让不同类以各自的方式响应同一方法调用。Edexcel 题目可能要求你识别 UML 图或代码片段中类之间的关系。


    8. File Handling and Exceptions | 文件处理与异常

    Programs often read from and write to text or binary files. Common operations are open, read, write, append and close; closing a file flushes buffers and releases resources. You should know the difference between overwriting a file and appending to the end.

    程序经常读写文本文件或二进制文件。常见操作有打开、读取、写入、追加和关闭;关闭文件会刷新缓冲区并释放资源。你应该知道覆盖文件与在末尾追加之间的区别。

    Exceptions handle runtime errors such as file not found, division by zero or invalid user input. A try-except block lets the program recover gracefully instead of crashing. For example, you can catch a FileNotFoundError and prompt the user to enter a valid filename.

    异常处理用于处理运行时错误,如文件未找到、除以零或无效用户输入。try-except 块让程序优雅地恢复,而不是崩溃。例如,你可以捕获 FileNotFoundError 并提示用户输入有效的文件名。

    Using a finally block ensures that cleanup code runs whether an exception occurred or not. This is especially useful for closing files or database connections. Exam questions sometimes ask you to complete a try-except-finally structure.

    使用 finally 块可以确保无论是否发生异常,清理代码都会运行。这对于关闭文件或数据库连接特别有用。考试题有时要求你

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

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

  • Edexcel A-Level Programming: Core Coding Techniques and Exam Skills | 爱德思 A-Level 编程:核心编码技巧与考试技能

    📚 Edexcel A-Level Programming: Core Coding Techniques and Exam Skills | 爱德思 A-Level 编程:核心编码技巧与考试技能

    In Edexcel A-Level Computer Science, programming is not just about typing code; it is about designing precise, efficient solutions to computational problems. This revision guide covers the core programming techniques you will need for Paper 1 and Paper 2, including data structures, algorithms, recursion, object-oriented principles, and exam strategies.

    在爱德思 A-Level 计算机科学中,编程不仅仅是输入代码,更是为计算问题设计精确、高效的解决方案。本复习指南涵盖 Paper 1 和 Paper 2 所需的核心编程技术,包括数据结构、算法、递归、面向对象原则以及考试策略。


    1. Computational Thinking and Problem Decomposition | 计算思维与问题分解

    Programming in Edexcel A-Level Computer Science begins with computational thinking: decompose a problem into smaller parts, recognise patterns, abstract away irrelevant detail, and design an algorithm before writing code.

    爱德思 A-Level 计算机科学中的编程始于计算思维:先将问题分解成更小的部分,识别模式,抽象掉无关细节,再在写代码之前设计算法。

    A good algorithm must be clear, finite, and precise. It should also be represented using pseudocode, flowcharts, or structured English so that examiners can follow your logic even if syntax is imperfect.

    好的算法必须清晰、有限且精确。它还应使用伪代码、流程图或结构化英语表示,这样即使语法不完美,考官也能理解你的逻辑。


    2. Variables, Constants and Data Types | 变量、常量与数据类型

    Variables store values that can change while a program runs, whereas constants hold fixed values. Every variable has a data type such as integer, real, Boolean, character, or string, and the choice of type affects memory use and the operations available.

    变量存储程序运行时可能变化的值,常量则保存固定值。每个变量都有数据类型,如整数、实数、布尔、字符或字符串,选择类型会影响内存使用和可执行的操作。

    Scope is also important: local variables exist only inside a function or procedure, while global variables can be accessed anywhere. Overusing global variables can make a program harder to debug and maintain.

    作用域也很重要:局部变量只存在于函数或过程内部,全局变量则可以在任何地方访问。过度使用全局变量会使程序更难调试和维护。


    3. Control Structures: Sequence, Selection, Iteration | 控制结构:顺序、选择与迭代

    Sequence means instructions run one after another. Selection uses if, else if, and switch/case to make decisions. Iteration repeats instructions using count-controlled loops such as FOR or condition-controlled loops such as WHILE.

    顺序意味着指令一条接一条执行。选择使用 if、else if 和 switch/case 来进行判断。迭代使用计数控制循环(如 FOR)或条件控制循环(如 WHILE)重复执行指令。

    Choosing the right loop matters: use a FOR loop when the number of repetitions is known in advance, and a WHILE loop when repetition depends on a condition that may change during execution.

    选择合适的循环很重要:当重复次数事先已知时使用 FOR 循环;当重复取决于执行过程中可能变化的条件时使用 WHILE 循环。


    4. Functions, Procedures and Parameters | 函数、过程与参数传递

    Functions and procedures are named blocks of code that promote modularity and reusability. A function returns a value, while a procedure does not, though both can accept parameters.

    函数和过程是命名代码块,能提高模块化和可重用性。函数返回一个值,过程不返回值,但两者都可以接受参数。

    Parameters can be passed by value or by reference. Pass by value copies the data, so changes inside the subroutine do not affect the original variable. Pass by reference shares the memory location, allowing the subroutine to modify the caller’s variable.

    参数可以按值传递或按引用传递。按值传递会复制数据,因此子程序内部的更改不会影响原始变量;按引用传递共享内存位置,子程序可以修改调用者的变量。


    5. Recursion and the Call Stack | 递归与调用栈

    Recursion is a technique where a function calls itself to solve a smaller version of the same problem. A correct recursive algorithm must have a base case to stop the recursion and a recursive case that moves towards the base case.

    递归是一种函数调用自身来解决同一问题更小版本的技术。正确的递归算法必须有停止递归的基准情形,以及向基准情形靠近的递归情形。

    For example, the factorial of n can be defined recursively as:

    例如,n 的阶乘可以递归定义为:

    n! = n × (n − 1)! for n > 1, and 1! = 1

    Each recursive call is placed on the call stack. If the base case is missing or unreachable, the stack can overflow, causing a runtime error.

    每次递归调用都会放入调用栈。如果缺少基准情形或基准情形不可达,栈可能会溢出,导致运行时错误。

    Recursion produces elegant solutions for tree traversal, backtracking, and divide-and-conquer algorithms, but it can be less memory-efficient than iteration.

    递归可以为树遍历、回溯和分治算法生成优雅的解决方案,但它可能比迭代占用更多内存。


    6. Arrays, Lists and Records | 数组、列表与记录

    Arrays store multiple values of the same data type under one name and use an index to access each element. Lists are similar but can often grow and shrink dynamically. Records store fields of different data types about one entity.

    数组在一个名称下存储多个相同数据类型的值,并使用索引访问每个元素。列表类似,但通常可以动态增减。记录存储一个实体的不同数据类型字段。

    A 2D array can model a grid or matrix, such as a game board or a spreadsheet. Accessing an element requires two indices: array[row][column].

    二维数组可以模拟网格或矩阵,例如游戏棋盘或电子表格。访问元素需要两个索引:array[行][列]。

    Knowing how to traverse arrays with loops, insert and delete elements, and search for a value is essential for Paper 2 algorithmic questions.

    了解如何用循环遍历数组、插入和删除元素以及搜索某个值,是 Paper 2 算法题的关键。


    7. Sorting and Searching Algorithms | 排序与查找算法

    Sorting algorithms arrange data in ascending or descending order. Bubble sort repeatedly compares adjacent items and swaps them if they are in the wrong order. Insertion sort builds a sorted portion by inserting each new item into its correct place.

    排序算法将数据按升序或降序排列。冒泡排序反复比较相邻项并在顺序错误时交换。插入排序通过将每个新项插入正确位置来构建已排序部分。

    Merge sort uses divide and conquer: it splits the list in half, sorts each half recursively, and then merges the two sorted halves. This gives a worst-case time complexity of O(n log₂ n), whereas bubble and insertion sorts are O(n²) in the worst case.

    归并排序使用分治法:将列表一分为二,递归地对每一半排序,然后合并两个有序半部分。它的最坏时间复杂度为 O(n log₂ n),而冒泡和插入排序的最坏情况是 O(n²)。

    Algorithm Best case Worst case Typical use
    Bubble sort O(n) O(n²) Simple, small data sets
    Insertion sort O(n) O(n²) Nearly sorted data
    Merge sort O(n log₂ n) O(n log₂ n) Large, stable sorting

    Searching can be linear, checking every item one by one, or binary, which works on sorted arrays by repeatedly halving the search interval. Binary search has O(log₂ n) time complexity.

    查找可以是线性,逐个检查每个项;也可以是二分,在有序数组上重复将搜索区间减半。二分查找的时间复杂度为 O(log₂ n)。


    8. Object-Oriented Programming Basics | 面向对象编程基础

    Object-oriented programming (OOP) organises code around classes and objects. A class is a blueprint that defines attributes and methods; an object is an instance of a class.

    面向对象编程围绕类和对象组织代码。类是定义属性和方法的蓝图;对象是类的实例。

    Encapsulation hides internal state and requires access through methods. Inheritance allows a child class to reuse and extend a parent class. Polymorphism lets different classes respond to the same method name in their own way.

    封装隐藏内部状态并要求通过方法访问。继承允许子类重用和扩展父类。多态让不同类以自己的方式响应同一个方法名。

    Constructors initialise new objects, and methods such as getters and setters provide controlled access to private attributes.

    构造函数初始化新对象,getter 和 setter

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

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

  • Mastering Edexcel A-Level Programming: Core Concepts and Exam Skills | 精通 Edexcel A-Level 编程:核心概念与考试技巧

    📚 Mastering Edexcel A-Level Programming: Core Concepts and Exam Skills | 精通 Edexcel A-Level 编程:核心概念与考试技巧

    This revision guide covers the programming knowledge required by the Edexcel A-Level Computer Science specification. It includes paradigms, data types, control flow, subroutines, recursion, data structures, algorithms, efficiency, object-oriented design, and testing strategies.

    本复习指南涵盖 Edexcel A-Level 计算机科学大纲要求的编程知识,包括范式、数据类型、控制流、子程序、递归、数据结构、算法、效率、面向对象设计和测试策略。

    1. Programming Paradigms and Decomposition | 编程范式与问题分解

    Edexcel questions often ask you to identify or compare programming paradigms. Procedural programming structures code into procedures or functions that carry out well-defined tasks. Object-oriented programming models real-world entities as classes with attributes and methods. Event-driven programming waits for events such as button clicks, sensor readings, or messages and executes handlers in response.

    Edexcel 考试常要求识别或比较编程范式。过程式编程将代码组织为执行明确任务的过程或函数。面向对象编程将现实世界实体建模为具有属性和方法的类。事件驱动编程等待按钮点击、传感器读数或消息等事件,并执行相应的处理程序。

    • Procedural — clear sequence of function calls (过程式——清晰的函数调用序列)
    • Object-oriented — data and behaviour combined in classes (面向对象——数据与行为封装在类中)
    • Event-driven — non-blocking response to user input (事件驱动——非阻塞响应用户输入)

    Decomposition is the process of breaking a large problem into smaller sub-problems. Good decomposition makes code easier to test, debug, reuse, and maintain.

    分解是将大问题拆分为更小子问题的过程。良好的分解使代码更易于测试、调试、复用和维护。


    2. Data Types, Variables and Constants | 数据类型、变量与常量

    You must be confident with primitive data types: integer, real/float, Boolean, character, and string. Edexcel pseudocode uses INTEGER, REAL, BOOLEAN, CHAR and STRING declarations. Variables can change value during execution, whereas constants hold values that cannot be modified after assignment.

    必须熟练掌握基本数据类型:整数、实数/浮点、布尔、字符和字符串。Edexcel 伪代码使用 INTEGER、REAL、BOOLEAN、CHAR 和 STRING 声明。变量在执行期间可以改变值,而常量在赋值后不能修改。

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

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

  • Mastering Programming for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学编程精讲

    📚 Mastering Programming for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学编程精讲

    Programming is the core problem-solving skill in Edexcel A-Level Computer Science. Whether you are tracing pseudocode in Paper 1 or building a coursework project, a secure grasp of constructs, data structures, algorithms and testing will directly determine your marks.

    编程是 Edexcel A-Level 计算机科学的核心问题解决技能。无论你是在 Paper 1 中追踪伪代码,还是在课程项目中构建程序,对结构、数据结构、算法和测试的扎实掌握都会直接影响你的得分。


    1. Programming Fundamentals | 编程基础

    Every Edexcel A-Level programming answer depends on three building blocks: sequence, selection and iteration. Sequence means instructions execute one after another; selection uses IF…THEN…ELSE…ENDIF or CASE statements; iteration is implemented with FOR, WHILE or REPEAT…UNTIL loops.

    每个 Edexcel A-Level 编程答案都依赖三个基本结构:顺序、选择和迭代。顺序是指令按顺序执行;选择使用 IF…THEN…ELSE…ENDIF 或 CASE 语句;迭代通过 FOR、WHILE 或 REPEAT…UNTIL 循环实现。

    Use constants for fixed values so programs are easier to maintain, and choose meaningful variable names such as totalScore rather than ts. Comments should explain why a complex step exists, not simply repeat the code.

    对固定值使用常量,程序更易于维护;变量名要选择有意义的名字,如 totalScore 而不是 ts。注释应当解释复杂步骤存在的原因,而不是简单重复代码。

    In Edexcel pseudocode, assignment is written with the left arrow ←. For example, total ← total + mark updates a running total by adding the current mark.

    在 Edexcel 伪代码中,赋值使用左箭头 ←。例如,total ← total + mark 通过加上当前分数更新累计总分。


    2. Data Types and Structures | 数据类型与结构

    Edexcel pseudocode uses integer, real, char, string and Boolean data types. Integer arithmetic truncates division results, while real arithmetic keeps the fractional part.

    Edexcel 伪代码使用整数、实数、字符、字符串和布尔数据类型。整数算术会截断除法结果,而实数算术保留小数部分。

  • Data type Meaning Edexcel example
    INTEGER whole number count ← 0
    Data Type Example Typical Use
    Integer 5, -12 Counters, whole-number arithmetic
    Real 3.14, -0.5 Decimal values, averages, scientific calculations
    Char ‘A’, ‘7’ Single character input or output
    String “hello” Names, messages, text

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

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

  • Edexcel A-Level Programming Essentials: Data, Control and Algorithms | Edexcel A-Level 编程核心:数据、控制与算法

    📚 Edexcel A-Level Programming Essentials: Data, Control and Algorithms | Edexcel A-Level 编程核心:数据、控制与算法

    Programming questions in Edexcel A-Level Computer Science are not only about writing code. You need to be confident with data types, variables, control structures, subroutines and standard algorithms, and you need to express your thinking clearly in pseudocode.

    在 Edexcel A-Level 计算机科学中,编程题不仅仅是编写代码。你需要熟练掌握数据类型、变量、控制结构、子程序和标准算法,并能够用伪代码清晰地表达思路。

    1. Programming Paradigms | 编程范式

    A programming paradigm is a style of programming. Edexcel expects you to identify procedural, object-oriented, event-driven and functional paradigms, and to compare their strengths for a given scenario.

    编程范式是一种编程风格。Edexcel 要求你识别过程式、面向对象、事件驱动和函数式范式,并比较它们在给定场景中的优势。

    Procedural programming uses a clear sequence of instructions and subroutines. Object-oriented programming uses classes and objects to model data and behaviour. Event-driven programming waits for events such as mouse clicks or key presses.

    过程式编程使用清晰的指令序列和子程序。面向对象编程使用类和对象来建模数据与行为。事件驱动编程等待鼠标点击或按键等事件。


    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.

    选择正确的数据类型可避免不必要的内存占用并保证操作可预测。你需要掌握的主要类型是整型、实型/浮点型、布尔型、字符型、字符串型,有时还有日期/时间型。

    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”

    For example, storing a phone number as a string avoids losing leading zero

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

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

  • Object-Oriented Programming in Python: Classes, Inheritance and Polymorphism | Python 面向对象编程:类、继承与多态

    📚 Object-Oriented Programming in Python: Classes, Inheritance and Polymorphism | Python 面向对象编程:类、继承与多态

    Object-oriented programming (OOP) is a core topic in the Edexcel A-Level Computer Science specification, particularly within Topic 4: Programming. This article explains the key OOP concepts in Python: classes, objects, encapsulation, inheritance, and polymorphism.

    面向对象编程(OOP)是 Edexcel A-Level 计算机科学规范中的核心主题之一,尤其是第 4 单元:编程。本文解释 Python 中的关键 OOP 概念:类、对象、封装、继承和多态。


    1. Introduction to Object-Oriented Programming | 面向对象编程简介

    Object-oriented programming is a paradigm that organises code around ‘objects’ rather than functions and logic alone. An object bundles data and the functions that operate on that data into a single unit.

    面向对象编程是一种围绕“对象”而非仅函数和逻辑组织代码的编程范式。对象将数据以及操作这些数据的函数捆绑为一个单元。

    The main benefits of OOP include easier maintenance, code reuse through inheritance, and the ability to model real-world entities more naturally. For A-Level exams, you need to explain these advantages and identify the building blocks: class, object, attribute, method, constructor, encapsulation, inheritance, and polymorphism.

    OOP 的主要优点包括更易于维护、通过继承实现代码复用,以及能够更自然地模拟现实世界实体。对于 A-Level 考试,你需要解释这些优点,并识别基本构建块:类、对象、属性、方法、构造器、封装、继承和多态。


    2. Classes and Objects in Python | Python 中的类与对象

    A class is a blueprint or template for creating objects. An object is an instance of a class. For example, the class Student defines the general properties and behaviours of all students, while each individual student is an object of that class.

    类是创建对象的蓝图或模板。对象是类的一个实例。例如,Student 类定义了所有学生的通用属性和行为,而每个具体的学生则是该类的一个对象。

    In Python, you define a class using the class keyword followed by the class name and a colon. The body of the class contains method definitions with an indented block. The simplest class can be written as class Student: pass.

    在 Python 中,使用 class 关键字后跟类名和冒号来定义类。类的主体包含缩进的方法定义。最简单的类可以写作 class Student: pass

    • Class = blueprint (e.g. Student)
    • Object = a real instance (e.g. Alice, Bob)
    • Class = 蓝图(例如学生)
    • Object = 真实实例(例如 Alice、Bob)

    3. The __init__ Constructor and self | __init__ 构造器与 self

    The __init__ method is a special constructor that runs automatically when an object is created. It initialises the object’s attributes with values passed as arguments.

    __init__ 方法是一个特殊的构造器,在创建对象时自动运行。它用传入的参数值初始化对象的属性。

    Inside every instance method, the first parameter self refers to the current object. Using self.name = name stores the parameter value into the object’s own attribute, so different objects keep separate data.

    在每个实例方法内部,第一个参数 self 指向当前对象。使用 self.name = name 将参数值存入对象自身的属性,从而使不同对象保存各自独立的数据。

    Example: def __init__(self, name, age): self.name = name; self.age = age. When you write student1 = Student('Alice', 17), Python calls Student.__init__(student1, 'Alice', 17) automatically.

    示例:def __init__(self, name, age): self.name = name; self.age = age。当你编写 student1 = Student('Alice', 17) 时,Python 会自动调用 Student.__init__(student1, 'Alice', 17)


    4. Attributes and Methods | 属性与方法

    Attributes are variables that belong to an object, and methods are functions that belong to an object. In a class, attributes are usually defined inside __init__, while methods are defined as functions inside the class body.

    属性是属于对象的变量,方法是属于对象的函数。在类中,属性通常在 __init__ 内部定义,而方法则定义为类主体内部的函数。

    There are two types of attributes: instance attributes (unique to each object, using self.) and class attributes (shared by all objects, written directly inside the class). A-level exam questions often ask you to distinguish between these.

    属性有两种类型:实例属性(每个对象独有,使用 self.)和类属性(所有对象共享,直接写在类内部)。A-level 考试题经常要求区分二者。

    For example, a class attribute school = 'Aleveler College' is the same for all objects, while self.name is different for each student. Accessing an attribute is done with dot notation: object.attribute.

    例如,类属性 school = 'Aleveler College' 对所有对象都是相同的,而 self.name 每个学生不同。使用点号访问属性:对象.属性


    5. Encapsulation and Access Modifiers | 封装与访问修饰符

    Encapsulation means hiding the internal state of an object and requiring all interaction to go through public methods. This protects data from being changed in unexpected ways and makes the code easier to debug.

    封装意味着隐藏对象的内部状态,并要求所有交互都通过公共方法进行。这可以保护数据不被以意外方式更改,并使代码更易于调试。

    In Python, encapsulation is implemented by naming conventions rather than strict access modifiers. A single leading underscore (_attribute) signals ‘protected’, while a double leading underscore (__attribute) triggers name mangling to make it harder to access from outside the class.

    在 Python 中,封装通过命名约定而非严格的访问修饰符实现。单下划线前缀(_attribute)表示“受保护”,双下划线前缀(__attribute)触发名称改编,使其难以从类外部访问。

    To provide controlled access, use getter and setter methods. For example, a get_age() method returns the age, and a set_age(new_age) method validates input before changing the value. The @property decorator can make getters and setters look like normal attribute access.

    为了提供受控访问,使用 getter 和 setter 方法。例如,get_age() 方法返回年龄,set_age(new_age) 方法在更改值之前验证输入。使用 @property 装饰器可以让 getter 和 setter 看起来像普通的属性访问。


    6. Inheritance: Building Class Hierarchies | 继承:构建类层次结构

    Inheritance allows a new class (child or subclass) to reuse the attributes and methods of an existing class (parent or superclass). This supports code reuse and models ‘is-a’ relationships, such as a Dog is an Animal.

    继承允许新类(子类)重用现有类(父类或超类)的属性和方法。这支持代码复用,并模拟“is-a”关系,例如 Dog 是一个 Animal。

    In Python, a subclass is defined by placing the parent class name in parentheses: class Dog(Animal):. The subclass automatically inherits all methods and attributes from the parent, but it can also add new ones or override existing ones.

    在 Python 中,通过在括号中放置父类名称来定义子类:class Dog(Animal):。子类自动继承父类的所有方法和属性,但它也可以添加新方法或覆盖现有方法。

    Exam questions may ask you to identify the superclass, subclass, and inherited members from a given code snippet, or to write a subclass that extends a given parent correctly.

    考试题可能会要求你从给定代码片段中识别超类、子类和继承的成员,或者编写一个正确扩展给定父类的子类。


    7. Method Overriding and the super() Function | 方法重写与 super() 函数

    Method overriding occurs when a subclass defines a method with the same name as a method in its parent class. The subclass version replaces the parent version for objects of the subclass, allowing more specific behaviour.

    方法重写发生在子类定义了与其父类中某个方法同名的方法时。对于子类的对象,子类版本会替换父类版本,从而允许更具体的行为。

    If you need to call the parent class’s version from within the overridden method, use the super() function. For example, super().__init__(name) calls the parent constructor before adding subclass-specific initialisation.

    如果需要在重写的方法内部调用父类的版本,请使用 super() 函数。例如,super().__init__(name) 在添加子类特定的初始化之前调用父类构造器。

    Using super() avoids duplicating code and ensures that the parent’s initialisation or validation still runs. This is a common pattern in object-oriented Python and appears frequently in A-level coding questions.

    使用 super() 可以避免重复代码,并确保父类的初始化或验证仍会运行。这是面向对象 Python 中的常见模式,经常出现在 A-level 编程题中。


    8. Polymorphism and Duck Typing | 多态与鸭子类型

    Polymorphism means ‘many forms’. In OOP, it allows different classes to provide their own implementation of the same method name, so the same code can work with objects of different types.

    多态意味着“多种形态”。在 OOP 中,它允许不同的类为相同的方法名提供各自的实现,因此同一代码可以适用于不同类型的对象。

    Python uses duck typing: if an object has the required method, it can be used regardless of its class. The saying ‘if it walks like a duck and quacks like a duck, then it is a duck’ summarises this idea.

    Python 使用鸭子类型:如果一个对象具有所需的方法,那么无论它属于哪个类都可以使用。谚语“如果它走路像鸭子,叫声像鸭子,那么它就是鸭子”概括了这一思想。

    For example, both Circle and Square classes may define an area() method. A function that calls shape.area() works with either class, demonstrating polymorphic behaviour without inheritance.

    例如,CircleSquare 类都可以定义 area() 方法。调用 shape.area() 的函数对两个类都适用,展示了无需继承的多态行为。


    9. Abstract Base Classes (ABCs) | 抽象基类(ABC)

    An abstract base class is a class that cannot be instantiated; its purpose is to define a common interface for subclasses. In Python, the abc module provides the ABC class and the @abstractmethod decorator.

    抽象基类是不能被实例化的类;其目的是为子类定义通用接口。在 Python 中,abc 模块提供了 ABC 类和 @abstractmethod 装饰器。

    Any subclass of an abstract class must override all abstract methods, otherwise the subclass also becomes abstract and cannot be instantiated. This enforces a contract for all derived classes.

    抽象类的任何子类都必须重写所有抽象方法,否则子类也会变成抽象类且无法实例化。这为所有派生类强制执行了一个契约。

    For Edexcel A-Level, you should be able to recognise the purpose of abstract classes and explain why they are useful in designing large programs with consistent interfaces.

    对于 Edexcel A-Level,你应该能够识别抽象类的用途,并解释为什么它们在设计具有一致接口的大型程序时很有用。


    10. OOP vs Procedural Programming: Exam Perspective | OOP 与过程式编程:考试视角

    Procedural programming organises code as a sequence of instructions and functions, while OOP organises code as interacting objects. Both paradigms can solve the same problems, but OOP is often preferred for large, complex systems because it improves modularity and maintainability.

    过程式编程将代码组织为一系列指令和函数,而 OOP 将代码组织为相互交互的对象。两种范式都可以解决相同的问题,但 OOP 通常更适合大型复杂系统,因为它提高了模块化和可维护性。

    In exam questions, you may be asked to compare the two paradigms, identify which is more suitable for a given scenario, or convert a short procedural script into an object-oriented version using classes and methods.

    在考试题中,你可能需要比较这两种范式,确定哪种更适合给定的场景,或者将一个简短的过程式脚本转换为使用类和方法的面向对象版本。

    Remember the key terms and their definitions: class, object, attribute, method, constructor, inheritance, polymorphism, encapsulation, and abstract class. Practise writing short Python class definitions by hand, because Edexcel coding questions often expect you to write or complete code in the exam.

    记住关键术语及其定义:类、对象、属性、方法、构造器、继承、多态、封装和抽象类。练习手写简短的 Python 类定义,因为 Edexcel 编程题常要求你在考试中编写或补全代码。

    Published by TutorHao | Computer Science Revision Series | aleveler.com

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

  • Programming Fundamentals and Algorithms for Edexcel A-Level | Edexcel A-Level 编程基础与算法精讲

    📚 Programming Fundamentals and Algorithms for Edexcel A-Level | Edexcel A-Level 编程基础与算法精讲

    Programming is a central component of the Edexcel A-Level Computer Science specification. It tests your ability to design, write, trace and evaluate code under exam conditions. This revision guide brings together the essential constructs, data structures, standard algorithms and object-oriented techniques you need to succeed in Paper 2 and the practical programming project.

    编程是 Edexcel A-Level 计算机科学考试的核心组成部分。它考查你在考试条件下设计、编写、追踪和评估代码的能力。本复习指南汇总了你在 Paper 2 和实践编程项目中取得成功所需的基本结构、数据结构、标准算法与面向对象技术。


    1. Variables, Data Types and Constants | 变量、数据类型与常量

    In Edexcel pseudocode and Python, a variable is a named memory location whose value can change during execution. Constants are fixed values declared with the keyword CONSTANT, and their identifiers are usually written in upper case.

    在 Edexcel 伪代码和 Python 中,变量是命名的内存位置,其值在执行过程中可以改变。常量是用关键字 CONSTANT 声明的固定值,其标识符通常用大写字母书写。

    Common data types include Integer, Real/Float, Boolean, Char, String, and Date. Choosing the correct type affects memory use and the operations available; for example, string concatenation uses ‘+’ while integer division uses DIV or //.

    常见数据类型包括整型、实型/浮点型、布尔型、字符型、字符串型和日期型。选择正确的类型会影响内存使用和可用的操作;例如,字符串连接使用 ‘+’,而整数除法使用 DIV 或 //。

    Arithmetic operators include +, -, *, /, MOD and DIV. Comparison operators are =, ≠, <, >, ≤ and ≥. Type conversion functions such as INT_TO_STRING and STRING_TO_INT are useful when handling user input.

    算术运算符包括 +、-、*、/、MOD 和 DIV。比较运算符为 =、≠、<、>、≤ 和 ≥。类型转换函数(如 INT_TO_STRING 和 STRING_TO_INT)在处理用户输入时非常有用。

    CONSTANT VAT_RATE ← 0.20
    price ← 50.00
    vat ← price × VAT_RATE


    2. Sequence, Selection and Iteration | 顺序、选择与迭代

    All algorithms can be built from three control structures: sequence, selection and iteration. Sequence executes statements one after another; selection uses IF…THEN…ELSE…ENDIF to make decisions; iteration repeats blocks using FOR, WHILE or REPEAT…UNTIL loops.

    所有算法都可以由三种控制结构构建:顺序、选择和迭代。顺序是一条接一条执行语句;选择使用 IF…THEN…ELSE…ENDIF 进行判断;迭代使用 FOR、WHILE 或 REPEAT…UNTIL 循环重复执行语句块。

    When choosing between loops, remember that a WHILE loop tests the condition before each iteration and may never execute, whereas a REPEAT…UNTIL loop tests after each iteration and executes at least once.

    在循环之间选择时,请记住 WHILE 循环在每次迭代之前测试条件,可能一次都不执行;而 REPEAT…UNTIL 循环在每次迭代之后测试条件,至少执行一次。

    A CASE statement can replace multiple IF…ELSEIF checks when the same variable is compared with several literal values. Nested structures are allowed, but deep nesting reduces readability and should be avoided where possible.

    当同一个变量与多个字面值比较时,CASE 语句可以替代多个 IF…ELSEIF 检查。允许嵌套结构,但深层嵌套会降低可读性,应尽可能避免。

    IF score ≥ 80 THEN
      grade ← ‘A’
    ELSE IF score ≥ 60 THEN
      grade ← ‘B’
    ELSE
      grade ← ‘C’
    ENDIF


    3. Arrays, Lists and 2D Structures | 数组、列表与二维结构

    Arrays and lists store multiple values under one identifier. A 1D array is indexed from 0 in Python or from 1 in some pseudocode; Edexcel pseudocode often uses 0-based indexing, so always check the question context.

    数组和列表在一个标识符下存储多个值。一维数组在 Python 中从 0 开始索引,而在某些伪代码中从 1 开始;Edexcel 伪代码通常使用 0 基索引,因此务必检查题目上下文。

    Common operations on arrays include traversing, inserting, deleting and searching. Inserting or deleting in the middle of an array requires shifting elements, which has O(n) time complexity.

    数组的常见操作包括遍历、插入、删除和搜索。在数组中间插入或删除需要移动元素,时间复杂度为 O(n)。

    A 2D array is a table of rows and columns, written as myArray[row, column]. Use nested loops to traverse it, with the outer loop controlling rows and the inner loop controlling columns.

    二维数组是由行和列组成的表格,写作 myArray[row, column]。使用嵌套循环遍历它,外层循环控制行,内层循环控制列。

    FOR i ← 0 TO rows-1
      FOR j ← 0 TO cols-1
        OUTPUT myArray[i, j]
      NEXT j
    NEXT i


    4. Functions and Procedures | 函数与过程

    Functions return a value and are called as part of an expression; procedures do not return a value and are called as standalone statements. Parameters can be passed by value or by reference, which affects whether changes persist outside the subroutine.

    函数返回一个值,并作为表达式的一部分调用;过程不返回值,作为独立语句调用。参数可以按值传递或按引用传递,这会影响更改是否在子程序之外保留。

    Local variables are declared inside a subroutine and exist only during its execution. Global variables can be accessed anywhere, but overusing them makes code harder to debug and reduces modularity.

    局部变量在子程序内部声明,仅在其执行期间存在。全局变量可以在任何地方访问,但过度使用会使代码更难调试并降低模块化程度。

    By default, scalar parameters are passed by value in most languages, meaning a copy is made. Arrays and objects are often passed by reference, so changes inside the subroutine can affect the original data structure.

    在大多数语言中,标量参数默认按值传递,即创建副本。数组和对象通常按引用传递,因此子程序内部的更改可能会影响原始数据结构。

    FUNCTION Add(a, b)
      RETURN a + b
    END FUNCTION


    5. Recursion and the Call Stack | 递归与调用栈

    A recursive subroutine calls itself with a smaller instance of the problem. Every recursive algorithm must have a base case to stop the recursion and a recursive case that reduces the problem size.

    递归子程序用问题的更小实例调用自身。每个递归算法必须有一个基本情况来停止递归,以及一个递归情况来缩小问题规模。

    Recursion uses the call stack to store return addresses and local variables. If the base case is missing or unreachable, the stack overflows, causing a runtime error.

    递归使用调用栈来存储返回地址和局部变量。如果基本情况缺失或无法到达,栈会溢出,导致运行时错误。

    Recursion often produces elegant solutions for problems such as factorial, Fibonacci and binary tree traversal. However, recursion can be less efficient than iteration because each call adds stack overhead and may recompute the same values.

    递归通常为阶乘、斐波那契和二叉树遍历等问题提供优雅的解决方案。然而,递归可能比迭代效率低,因为每次调用都会增加栈开销,并可能重复计算相同的值。

    FUNCTION Factorial(n)
      IF n = 0 THEN
        RETURN 1
      ELSE
        RETURN n × Factorial(n-1)
      ENDIF
    END FUNCTION


    6. File Handling and Exception Management | 文件处理与异常管理

    External data is stored in text or binary files. Typical operations include opening a file in read, write or append mode, reading lines with READLINE, writing with PRINT or WRITELINE, and closing the file with CLOSE.

    外部数据存储在文本或二进制文件中。典型操作包括以读、写或追加模式打开文件,用 READLINE 读取行,用 PRINT 或 WRITELINE 写入,以及用 CLOSE 关闭文件。

    Always close files after use to flush buffers and release file handles. The EOF marker indicates the end of a file, and loops should stop reading when EOF is reached.

    使用后始终关闭文件以刷新缓冲区并释放文件句柄。EOF 标记表示文件结束,循环应在到达 EOF 时停止读取。

    Exception handling uses TRY…EXCEPT…FINALLY to manage runtime errors such as a missing file or invalid numeric input. This prevents the program from crashing and allows graceful recovery.

    异常处理使用 TRY…EXCEPT…FINALLY 来管理运行时错误,例如文件缺失或无效的数字输入。这可以防止程序崩溃并允许优雅地恢复。

    TRY
      OPEN ‘data.txt’ FOR READ
      WHILE NOT EOF
        READLINE
      ENDWHILE
    EXCEPT IOError
      OUTPUT ‘File not found’
    FINALLY
      CLOSE FILE
    ENDTRY


    7. Searching Algorithms: Linear and Binary Search | 查找算法:线性搜索与二分搜索

    Linear search checks each element in turn until the target is found or the list ends. It works on unsorted data and has a worst-case time complexity of O(n).

    线性搜索依次检查每个元素,直到找到目标或列表结束。它适用于未排序的数据,最坏情况时间复杂度为 O(n)。

    Binary search repeatedly halves a sorted list by comparing the middle element with the target. It has O(log₂ n) time complexity but requires the data to be sorted first.

    二分搜索通过将中间元素与目标比较,反复将已排序列表减半。它的时间复杂度为 O(log₂ n),但要求数据先排序。

    In a binary search, if the target is less than the middle value, discard the upper half; if greater, discard the lower half. This process continues until the target is found or the search interval is empty.

    在二分搜索中,如果目标小于中间值,则丢弃上半部分;如果大于中间值,则丢弃下半部分。这个过程持续到找到目标或搜索区间为空。

    WHILE low ≤ high
      mid ← (low + high) DIV 2
      IF arr[mid] = target THEN RETURN mid
      IF arr[mid] < target THEN low ← mid + 1
      ELSE high ← mid – 1
    ENDWHILE


    8. Sorting Algorithms: Bubble, Insertion, Merge | 排序算法:冒泡、插入与归并

    Bubble sort compares adjacent pairs and swaps them if they are out of order, moving the largest value to the end on each pass. It is stable but inefficient with O(n²) average time.

    冒泡排序比较相邻元素并在顺序错误时交换它们,每次遍历将最大值移动到末尾。它是稳定的,但平均时间复杂度为 O(n²),效率较低。

    Insertion sort builds a sorted sublist by inserting each new element into its correct position. It performs well on nearly sorted data and is also stable.

    插入排序通过将每个新元素插入到正确位置来构建已排序子列表。它对接近有序的数据表现良好,并且也是稳定的。

    Merge sort uses a divide-and-conquer approach, recursively splitting the list in half, sorting each half, and merging the results. It guarantees O(n log₂ n) time but uses extra memory.

    归并排序使用分治法,递归地将列表分成两半,对每半排序,然后合并结果。它保证 O(n log₂ n) 时间,但使用额外内存。

    A stable sorting algorithm preserves the relative order of equal elements. This matters when sorting by one key and then another, such as sorting students by name and then by grade.

    稳定的排序算法会保留相等元素的相对顺序。当按一个关键字排序后再按另一个关键字排序时,这一点很重要,例如先按姓名再按成绩对学生排序。


    9. Big O Notation and Algorithm Efficiency | 大 O 表示法与算法效率

    Big O notation describes how the time or space required by an algorithm grows as the input size n increases. Constant time is O(1), linear is O(n), quadratic is O(n²), and logarithmic is O(log₂ n).

    大 O 表示法描述算法所需的时间或空间如何随着输入规模 n 的增长而增长。常数时间为 O(1),线性为 O(n),二次方为 O(n²),对数为 O(log₂ n)。

    In an exam, you may be asked to compare algorithms for the same task. Always consider the best, average and worst cases, and whether extra memory is required.

    在考试中,你可能会被要求比较解决同一任务

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

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

  • A-Level Edexcel Programming: Constructs, Data Structures & Algorithms | A-Level Edexcel 编程:结构、数据结构与算法

    📚 A-Level Edexcel Programming: Constructs, Data Structures & Algorithms | A-Level Edexcel 编程:结构、数据结构与算法

    Programming in the Edexcel A-Level Computer Science specification is not just about writing code; it demands a precise understanding of language constructs, data representation, control flow and algorithm efficiency. This article consolidates the core programming concepts that frequently appear in Paper 1 and Paper 2 questions, with worked explanations and common exam traps.

    在 Edexcel A-Level 计算机科学大纲中,编程不只是写代码,还要求准确理解语言结构、数据表示、控制流程和算法效率。本文整合了试卷一和试卷二中常见的核心编程概念,并配有详细解释与常见考试陷阱。


    1. Programming Paradigms and Language Types | 编程范式与语言类型

    Edexcel expects candidates to distinguish between imperative, object-oriented, functional and logic paradigms. Imperative code uses sequences, selection and iteration to change program state; object-oriented code organises state and behaviour into classes and objects; functional code treats computation as evaluation of mathematical functions and avoids side effects; logic programming expresses rules and queries.

    Edexcel 要求考生区分命令式、面向对象、函数式和逻辑式编程范式。命令式代码使用顺序、选择和迭代改变程序状态;面向对象代码将状态和行为组织为类和对象;函数式代码把计算视为数学函数的求值并避免副作用;逻辑编程则表达规则和查询。

    High-level languages are translated by compilers or interpreters. A compiler translates the whole source code into machine code before execution, while an interpreter translates and executes line by line. Bytecode languages such as Java use both: source code is compiled to bytecode, then interpreted or just-in-time compiled by a virtual machine.

    高级语言由编译器或解释器翻译。编译器在执行前将整个源代码翻译为机器码,而解释器逐行翻译并执行。Java 等字节码语言两者都用:源代码先编译为字节码,再由虚拟机解释或即时编译。


    2. Data Types, Variables and Constants | 数据类型、变量与常量

    Programs store values in variables and constants. Primitive data types include integer, real/floating-point, Boolean, character and string. Edexcel questions often test type conversion, overflow, and the difference between assignment and comparison (for example = vs == in many languages).

    程序将值存储在变量和常量中。基本数据类型包括整型、实型/浮点型、布尔型、字符型和字符串型。Edexcel 题目常考类型转换、溢出,以及赋值与比较的区别(例如许多语言中 = 与 == 的不同)。

    Constants are declared with a fixed value that cannot change during execution, improving maintainability and reducing magic numbers. Variables should have meaningful identifiers and appropriate scope: local variables exist only inside a function or block; global variables exist throughout the program but can make debugging harder.

    常量声明为在执行期间不能更改的固定值,能提高可维护性并减少魔法数。变量应有有意义的标识符和合适的作用域:局部变量仅存在于函数或块内部;全局变量在整个程序中存在,但会增加调试难度。


    3. Control Structures: Sequence, Selection, Iteration | 控制结构:顺序、选择与迭代

    All procedural programs are built from three control structures: sequence, selection and iteration. Selection is implemented with IF, ELSE IF, ELSE or switch/case statements. Nested selection must use clear indentation and Boolean operators such as AND, OR, NOT.

    所有过程式程序都由三种控制结构构建:顺序、选择和迭代。选择通过 IF、ELSE IF、ELSE 或 switch/case 语句实现。嵌套选择必须使用清晰的缩进和 AND、OR、NOT 等布尔运算符。

    Iteration includes definite loops, such as FOR loops that run a known number of times, and indefinite loops, such as WHILE and REPEAT…UNTIL. WHILE loops test the condition before each iteration and may run zero times; REPEAT…UNTIL loops test after each iteration and always run at least once.

    迭代包括确定循环(如已知运行次数的 FOR 循环)和不确定循环(如 WHILE 和 REPEAT…UNTIL)。WHILE 循环在每次迭代前测试条件,可能一次也不运行;REPEAT…UNTIL 循环在每次迭代后测试条件,因此至少运行一次。

    WHILE score < 0 OR score > 100
    OUTPUT “Invalid score, re-enter: “
    INPUT score
    ENDWHILE


    4. Functions, Procedures and Parameters | 函数、过程与参数

    A function returns a value; a procedure performs a task but does not return a value. Both help decompose large problems into smaller, reusable modules. Parameters allow values to be passed into a subprogram.

    函数返回一个值;过程执行任务但不返回值。两者都有助于将大问题分解为更小、可复用的模块。参数允许将值传入子程序。

    There are two main parameter passing methods: by value and by reference. Pass by value copies the argument, so changes inside the subprogram do not affect the original variable. Pass by reference passes the address, so changes modify the original. Edexcel pseudocode may use keywords such as BYVAL and BYREF.

    参数传递主要有两种方式:按值传递和按引用传递。按值传递会复制实参,因此子程序内部的更改不会影响原变量。按引用传递传递的是地址,因此更改会修改原变量。Edexcel 伪代码可能使用 BYVAL 和 BYREF 等关键字。

    Recursion is a technique where a function calls itself. Every recursive algorithm must have a base case to stop the recursion and a recursive case that reduces the problem size. For example, factorial n = n × (n−1)! with base case 0! = 1.

    递归是一种函数调用自身的技术。每个递归算法必须有停止递归的基准情形,以及减小问题规模的递归情形。例如,阶乘 n = n × (n−1)!,基准情形为 0! = 1。

    n! = n × (n − 1)! for n > 0, with 0! = 1


    5. Recursion and Stack Frames | 递归与栈帧

    When a recursive function runs, each call creates a new stack frame containing its parameters and local variables. These frames are pushed onto the call stack. If the base case is missing or unreachable, the stack overflows and the program crashes.

    当递归函数运行时,每次调用都会创建一个新的栈帧,包含其参数和局部变量。这些帧被压入调用栈。如果缺少基准情形或基准情形不可达,栈就会溢出,程序崩溃。

    Recursion can produce elegant solutions for tree traversal, binary search and divide-and-conquer algorithms. However, it can be less efficient in memory than iteration because of the stack usage. Some problems, such as Fibonacci, have overlapping subproblems, so recursion without memoisation repeats work.

    递归可以为树遍历、二分查找和分治算法提供优雅的解决方案。但是,由于栈的使用,递归在内存上可能不如迭代高效。某些问题(如斐波那契)存在重叠子问题,因此不带备忘录的递归会重复计算。


    6. Data Structures: Arrays, Lists, Stacks and Queues | 数据结构:数组、列表、栈与队列

    Arrays store elements of the same type in contiguous memory locations and allow direct access by index in O(1) time. Static arrays have a fixed size, while dynamic arrays can resize. A 2D array is often used to represent tables or matrices.

    数组将相同类型的元素存储在连续的内存位置中,并允许通过索引在 O(1) 时间内直接访问。静态数组大小固定,动态数组可以调整大小。二维数组常用于表示表格或矩阵。

    Stacks and queues are abstract data types. A stack is a LIFO (last in, first out) structure with push and pop operations; it is used in expression evaluation, backtracking and call stacks. A queue is a FIFO (first in, first out) structure with enqueue and dequeue operations; it is used in scheduling and breadth-first search.

    栈和队列是抽象数据类型。栈是 LIFO(后进先出)结构,具有 push 和 pop 操作;用于表达式求值、回溯和调用栈。队列是 FIFO(先进先出)结构,具有 enqueue 和 dequeue 操作;用于调度和广度优先搜索。


    7. Object-Oriented Programming | 面向对象编程

    Object-oriented programming (OOP) models real-world entities as objects. A class is a blueprint that defines attributes (data) and methods (behaviours). An object is an instance of a class. Encapsulation hides internal state and exposes only necessary methods.

    面向对象编程(OOP)将现实世界的实体建模为对象。类是定义属性(数据)和方法(行为)的蓝图。对象是类的实例。封装隐藏内部状态,仅公开必要的方法。

    Inheritance allows a subclass to reuse and extend the attributes and methods of a superclass, promoting code reuse and polymorphism. Polymorphism lets different classes respond to the same method name in different ways. Composition is often preferred over deep inheritance because it is more flexible.

    继承允许子类复用并扩展超类的属性和方法,促进代码复用和多态。多态使不同类能够以不同方式响应同一方法名。组合通常比深层继承更受青睐,因为它更灵活。


    8. Error Handling, Validation and Testing | 错误处理、验证与测试

    Robust programs anticipate invalid input and runtime errors. Input validation checks data against rules such as range, type, length and format. Edexcel questions may ask you to write pseudocode that uses WHILE loops for validation, or to identify logic, syntax and runtime errors.

    健壮的程序会预判无效输入和运行时错误。输入验证根据范围、类型、长度和格式等规则检查数据。Edexcel 题目可能要求你编写使用 WHILE 循环进行验证的伪代码,或识别逻辑错误、语法错误和运行时错误。

    Testing strategies include normal, boundary and erroneous test data. Boundary values such as minimum, maximum, just below and just above a limit often reveal off-by-one errors. Trace tables are used to track variable values line by line and locate faults.

    测试策略包括正常、边界和错误测试数据。边界值(如最小值、最大值、刚好低于和刚好高于限制)往往能暴露差一错误。跟踪表用于逐行记录变量值并定位错误。


    9. Algorithm Analysis and Big O Notation | 算法分析与大 O 表示法

    Algorithm efficiency is measured by time and space complexity. Big O notation describes the upper bound of growth as input size n increases. Common complexities include O(1), O(log n), O(n), O(n log n), O(n²) and O(2ⁿ).

    算法效率通过时间复杂度和空间复杂度来衡量。大 O 表示法描述随着输入规模 n 增大,增长的上界。常见复杂度包括 O(1)、O(log n)、O(n)、O(n log n)、O(n²) 和 O(2ⁿ)。

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

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

  • Mastering Edexcel A-Level Programming: From Core Constructs to Algorithms | 精通Edexcel A-Level编程:从核心结构到算法

    📚 Mastering Edexcel A-Level Programming: From Core Constructs to Algorithms | 精通Edexcel A-Level编程:从核心结构到算法

    This article consolidates the core programming ideas assessed in Edexcel A-Level Computer Science. It is suitable for revision of Paper 2 topics and for strengthening your programming project skills.

    本文整合了Edexcel A-Level计算机科学考试中的核心编程思想。它适用于Paper 2主题复习,也有助于加强你的编程项目能力。

    1. Variables, Constants and Data Types | 变量、常量与数据类型

    A variable is a named storage location whose value can change during execution. A constant is fixed once assigned, and using constants improves maintainability by preventing accidental modification.

    变量是一个命名的存储位置,其值在执行过程中可以改变。常量在赋值后固定不变,使用常量可防止意外修改并提高可维护性。

    Edexcel pseudocode commonly uses the five standard data types: Integer, Real/Float, Boolean, Character, and String. Choosing the correct type affects memory usage and the operations that can be performed.

    Edexcel伪代码通常使用五种标准数据类型:整数、实数/浮点、布尔、字符和字符串。选择正确的类型会影响内存使用以及可以执行的操作。

    Type conversions may be implicit or explicit. In many languages, dividing two integers may produce a real result, while explicit casting such as INT(3.7) truncates the decimal part.

    类型转换可以是隐式的或显式的。在许多语言中,两个整数相除可能产生实数结果,而显式转换如INT(3.7)会截断小数部分。


    2. Selection and Iteration | 选择与迭代

    Selection uses IF…THEN…ELSE constructs to choose between alternative paths. Nested IF statements can express multi-branch logic, but CASE/SWITCH structures are often clearer.

    选择结构使用IF…THEN…ELSE来在多个路径之间进行选择。嵌套IF可以表达多分支逻辑,但CASE/SWITCH结构通常更清晰。

    Iteration repeats a block of code. Definite iteration (FOR loops) runs a known number of times, while indefinite iteration (WHILE and REPEAT…UNTIL) continues until a condition changes.

    迭代重复执行一段代码。确定迭代(FOR循环)运行已知次数,不确定迭代(WHILE和REPEAT…UNTIL)一直持续到条件改变。

    When comparing loop types, remember that a WHILE loop checks the condition at the start, so it may execute zero times. A REPEAT…UNTIL loop checks at the end, so the body always runs at least once.

    比较循环类型时,记住WHILE循环在开始时检查条件,因此可能执行零次。REPEAT…UNTIL循环在结束时检查条件,所以循环体至少执行一次。


    3. Arrays, Lists and Records | 数组、列表与记录

    An array is a finite, ordered collection of elements of the same data type. Arrays allow direct access by index, usually starting at 0, which gives O(1) read/write time.

    数组是一个有限的、有序的、同类型元素集合。数组允许按索引直接访问,通常从0开始,因此读写时间为O(1)。

    Lists are dynamic structures that can grow and shrink. They support insertion and deletion more flexibly than static arrays, though access to an element by position may be O(n) in a linked implementation.

    列表是可以动态增长和缩小的结构。它们支持比静态数组更灵活的插入和删除,但在链式实现中按位置访问元素可能需要O(n)时间。

    A record combines fields of different types under one name, such as a Student record containing name, age and grade. It is a simple way to model real-world entities.

    记录将不同类型的字段组合在一个名称下,例如包含姓名、年龄和成绩的Student记录。它是建模现实世界实体的一种简单方式。


    4. Functions, Procedures and Parameter Passing | 函数、过程与参数传递

    A function returns a value, while a procedure performs a task without returning a value. Edexcel pseudocode often uses SUBROUTINE for reusable blocks.

    函数返回一个值,而过程执行任务但不返回值。Edexcel伪代码通常使用SUBROUTINE表示可重用代码块。

    Parameters can be passed by value or by reference. By value copies the argument, so changes inside the routine do not affect the original. By reference passes the address, so modifications persist.

    参数可以按值传递或按引用传递。按值传递会复制实参,因此例程内部的更改不会影响原始变量。按引用传递会传递地址,因此修改会保留。

    Using meaningful identifiers, local variables and clear pre/post-conditions makes subroutines easier to test and reuse. Modular programming supports divide-and-conquer problem solving.

    使用有意义的标识符、局部变量和明确的前置/后置条件使得子程序更易于测试和复用。模块化编程支持分而治之的问题求解。


    5. Recursion and the Call Stack | 递归与调用栈

    A recursive subroutine calls itself with a smaller input. Every valid recursive solution needs a base case to stop the recursion and a recursive case that moves toward the base case.

    递归子程序用更小的输入调用自身。每个有效的递归方案都需要一个停止递归的基本情况,以及一个向基本情况推进的递归情况。

    Each recursive call is placed on the call stack. The stack stores return addresses, parameters and local variables. If the base case is missing or unreachable, stack overflow can occur.

    每个递归调用都会放入调用栈。栈保存返回地址、参数和局部变量。如果缺少基本情况或基本情况不可达,就可能发生栈溢出。

    Recursion can be elegant for problems such as factorial, Fibonacci and tree traversal, but it may use more memory than an equivalent iterative solution.

    递归对于阶乘、斐波那契和树遍历等问题可能十分简洁,但它可能比等价的迭代方案使用更多内存。


    6. Searching Algorithms: Linear and Binary Search | 搜索算法:线性搜索与二分搜索

    Linear search checks each element in order. It works on unsorted data and has O(n) worst-case time. Binary search requires sorted data and repeatedly halves the search interval.

    线性搜索按顺序检查每个元素。它适用于未排序数据,最坏情况时间复杂度为O(n)。二分搜索要求数据已排序,并反复将搜索区间减半。

    For binary search, compare the target with the middle element. If it is smaller, search the left half; if larger, search the right half. The maximum number of comparisons is about log₂ n + 1.

    对于二分搜索,将目标值与中间元素比较。如果目标较小则搜索左半部分;如果较大则搜索右半部分。最大比较次数约为log₂ n + 1。

    Binary search time = O(log n)

    二分搜索时间 = O(log n)


    7. Sorting Algorithms: Bubble, Insertion and Merge Sort | 排序

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

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

  • Object-Oriented Programming (OOP) Essentials for Edexcel A-Level | 面向对象编程核心(Edexcel A-Level)

    📚 Object-Oriented Programming (OOP) Essentials for Edexcel A-Level | 面向对象编程核心(Edexcel A-Level)

    Object-oriented programming is a central paradigm in the Edexcel A-Level Programming unit, requiring learners to move beyond linear scripts and design software using interacting objects. This article revises the core OOP principles, common syntax patterns and the assessment style you can expect in the exam.

    面向对象编程是 Edexcel A-Level 编程单元的核心范型,要求学习者超越线性脚本,使用相互协作的对象来设计软件。本文复习面向对象的核心原则、常见语法模式以及考试中可能遇到的题型。

    1. Course Context and Assessment | 课程背景与考核方式

    In the Edexcel A-Level Programming specification (Paper 2 or Unit 2 depending on your pathway), OOP is assessed through short-answer questions, trace-table tasks, and extended responses that ask you to design or evaluate class hierarchies.

    在 Edexcel A-Level 编程大纲中(试卷 2 或单元 2,取决于课程路径),面向对象编程通过简答题、跟踪表任务和扩展回答来评估,要求你设计或评估类层次结构。

    Typical mark allocations range from 1-mark definitions of keywords such as ‘encapsulation’ to 6-mark questions comparing inheritance with composition.

    典型分值从关键词定义(如”封装”)的 1 分题,到比较继承与组合的 6 分题不等。

    You should be confident writing basic class skeletons, identifying errors in given code, and explaining how OOP principles improve maintainability.

    你应该能熟练编写基本类框架、识别给定代码中的错误,并解释 OOP 原则如何提高可维护性。


    2. From Procedural to Object-Oriented | 从过程式到面向对象

    Procedural programming organises code as a sequence of instructions and reusable functions, while OOP bundles data and behaviour together into classes.

    过程式编程将代码组织为一系列指令和可复用函数,而面向对象编程将数据和行为捆绑到类中。

    The key difference is that an object has state (attribute values) and behaviour (methods) that act on that state, allowing more natural modelling of real-world systems.

    关键区别在于对象具有状态(属性值)和行为(作用于状态的方法),从而更自然地建模现实世界系统。

    For example, a BankAccount object can have a balance attribute and deposit() and withdraw() methods, rather than passing a balance variable to separate functions.

    例如,一个 BankAccount 对象可以拥有 balance 属性和 deposit()、withdraw() 方法,而不是将 balance 变量传递给独立函数。


    3. Classes and Objects | 类与对象

    A class is a blueprint or template that defines the attributes and methods common to all objects of that type.

    类是一份蓝图或模板,定义了该类型所有对象共有的属性和方法。

    An object is an instance of a class, created at runtime with its own copies of attribute values.

    对象是类的一个实例,在运行时创建,拥有自己的属性值副本。

    In Python, class Dog: defines the class, while d = Dog() creates an instance called d.

    在 Python 中,class Dog: 定义类,而 d = Dog() 创建一个名为 d 的实例。

    In Java, the equivalent is public class Dog { } and Dog d = new Dog();.

    在 Java 中,等价写法是 public class Dog { } 和 Dog d = new Dog();。


    4. Attributes and Methods | 属性与方法

    Attributes store the state of an object and are typically declared inside the constructor or at the top of the class.

    属性存储对象的状态,通常在构造函数内或类顶部声明。

    Methods define the behaviour of an object and usually access or modify attributes through a self or this reference.

    方法定义对象的行为,通常通过 self 或 this 引用来访问或修改属性。

    In Python, you write def bark(self): print(‘Woof’), while in Java you write public void bark() { System.out.println(“Woof”); }.

    在 Python 中,写 def bark(self): print(‘Woof’),而在 Java 中写 public void bark() { System.out.println(“Woof”); }。

    There are also class attributes (static fields) shared by all instances, but instance attributes are the most common exam focus.

    还有由所有实例共享的类属性(静态字段),但实例属性是最常见的考试重点。


    5. Encapsulation and Access Modifiers | 封装与访问修饰符

    Encapsulation means keeping an object’s internal data private and providing controlled access through public methods, often called getters and setters.

    封装意味着将对象的内部数据保持私有,并通过公共方法(通常称为 getter 和 setter)提供受控访问。

    This protects the integrity of the data because validation can be placed inside the setter, preventing impossible states such as a negative age.

    这保护了数据的完整性,因为可以在 setter 中加入验证,防止出现负年龄等不可能的状态。

    Java uses private, public and protected keywords, while Python conventionally uses a single underscore prefix (_balance) to signal ‘protected’ but does not enforce it strictly.

    Java 使用 private、public 和 protected 关键字,而 Python 传统上使用单下划线前缀(_balance)来表示”受保护”,但并不严格强制。

    In exams, you may be asked to explain why directly exposing attributes is considered poor practice and how encapsulation supports validation and maintenance.

    考试中可能会要求你解释为什么直接暴露属性是不良实践,以及封装如何支持验证和维护。


    6. Constructors and Instantiation | 构造函数与实例化

    A constructor is a special method that initialises a new object, setting the initial values of attributes.

    构造函数是一种特殊方法,用于初始化新对象,设置属性的初始值。

    In Python, the constructor is named __init__ and takes self as the first parameter, e.g. def __init__(self, name, age): self.name = name.

    在 Python 中,构造函数名为 __init__,第一个参数是 self,例如 def __init__(self, name, age): self.name = name。

    In Java, the constructor has the same name as the class and no return type: public Dog(String name) { this.name = name; }.

    在 Java 中,构造函数与类同名且没有返回类型:public Dog(String name) { this.name = name; }。

    Default constructors are provided automatically if no constructor is written, but once you define a parameterised constructor the default disappears unless you write it again.

    如果没有编写构造函数,会自动提供默认构造函数,但一旦定义了带参数的构造函数,默认构造函数就会消失,除非重新编写。


    7. Inheritance and Subclasses | 继承与子类

    Inheritance allows a new class (subclass) to reuse, extend or override the attributes and methods of an existing class (superclass).

    继承允许新类(子类)复用、扩展或重写现有类(超类)的属性和方法。

    You indicate inheritance in Python with class Child(Parent): and in Java with class Child extends Parent { }.

    在 Python 中用 class Child(Parent): 表示继承,在 Java 中用 class Child extends Parent { }。

    A classic exam example is a superclass Vehicle with subclasses Car and Motorcycle that inherit the start() method but add their own characteristics.

    经典的考试示例是超类 Vehicle 和子类 Car、Motorcycle,子类继承 start() 方法但添加自己的特征。

    Constructors of subclasses must call the superclass constructor, using super().__init__(…) in Python or super(…) in Java, to ensure inherited attributes are set up.

    子类的构造函数必须调用超类构造函数,使用 Python 的 super().__init__(…) 或 Java 的 super(…),以确保继承的属性被正确设置。


    8. Polymorphism and Overriding | 多态与方法重写

    Polymorphism means ‘many forms’ and allows the same method call to behave differently depending on the object’s actual class.

    多态意为”多种形态”,允许相同的方法调用根据对象的实际类表现出不同的行为。

    Method overriding occurs when a subclass defines a method with the same signature as a superclass method, replacing its implementation for subclass objects.

    方法重写发生在子类定义与超类方法签名相同的方法时,为子类对象替换该方法的实现。

    For example, a list of Shape objects may contain Circle and Square instances, and calling shape.area() dispatches to the correct override at runtime.

    例如,一个 Shape 对象列表可能包含 Circle 和 Square 实例,调用 shape.area() 在运行时分派到正确的重写方法。

    In Python, polymorphism is achieved dynamically by simply defining a method with the same name; in Java, use @Override annotation for clarity.

    在 Python 中,多态通过动态地定义同名方法实现;在 Java

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

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

  • Programming Fundamentals: Variables, Data Types and Control Structures | 编程基础:变量、数据类型与控制结构

    📚 Programming Fundamentals: Variables, Data Types and Control Structures | 编程基础:变量、数据类型与控制结构

    In Edexcel A Level Computer Science, the ‘Programming’ topic focuses on the building blocks needed to design and write reliable programs. This article summarises variables, data types, control structures, subroutines, and recursion, with clear links to pseudocode and the assessment objectives.

    在 Edexcel A Level 计算机科学中,“编程”主题聚焦于设计和编写可靠程序所需的基础构件。本文总结变量、数据类型、控制结构、子程序与递归,并结合伪代码与考核目标进行讲解。


    1. Variables and Constants | 变量与常量

    In programming, a variable is a named location in memory that stores a value. The value can be read, updated, or used in expressions. Most languages require a variable to be declared before use, and some require an explicit data type.

    在编程中,变量是内存中命名的存储位置,用于保存数值。该值可以被读取、更新或用于表达式。大多数语言要求变量在使用前声明,有些语言还要求明确指定数据类型。

    A constant is a value that remains unchanged throughout the execution of a program. In pseudocode, constants are often declared using the keyword CONST. They help avoid ‘magic numbers’ in code.

    常量是在程序执行过程中保持不变的值。在伪代码中,常量通常使用关键字 CONST 声明。它们有助于避免代码中出现“魔法数字”。

    • Variables are mutable; constants are immutable. | 变量可变;常量不可变。
    • Always initialise variables before reading them. | 读取变量前务必先初始化。
    • Use meaningful names such as customerAge rather than x. | 使用有意义的名称,如 customerAge,而不是 x

    2. Primitive Data Types | 原始数据类型

    Primitive data types are the basic categories of value that a programming language provides. The most common types are integer, real (floating-point), Boolean, and character.

    原始数据类型是编程语言提供的基本值类别。最常见的类型有整型、实数型(浮点型)、布尔型和字符型。

    Each type uses a different amount of memory and supports different operations. For example, integers support whole-number arithmetic, while reals support fractional arithmetic.

    每种类型占用不同的内存并支持不同的操作。例如,整型支持整数运算,而实数型支持小数运算。

    Data type 中文名称 Example values 更多咨询请联系16621398022(同微信)

  • Operators and Expressions in Programming | 编程中的运算符与表达式

    📚 Operators and Expressions in Programming | 编程中的运算符与表达式

    Operators are the symbols that tell a computer to perform specific mathematical, relational or logical operations. In Edexcel A-Level Computer Science, you must be able to read, write and trace expressions that combine operators and operands.

    运算符是告诉计算机执行特定数学、关系或逻辑操作的符号。在 Edexcel A-Level 计算机科学中,你必须能够阅读、编写并追踪结合了运算符和操作数的表达式。

    1. Why Operators Matter | 为什么运算符重要

    Operators form the core of every executable instruction. Without them, a program could store data but never calculate, compare or decide.

    运算符构成了每条可执行指令的核心。没有它们,程序只能存储数据,却无法计算、比较或做出决策。

    • Arithmetic operators build formulas for prices, coordinates and counters. 算术运算符用于为价格、坐标和计数器构建公式。
    • Comparison operators drive conditional statements such as IF and WHILE. 比较运算符驱动 IF 和 WHILE 等条件语句。
    • Logical operators combine multiple true/false conditions in selection. 逻辑运算符在选择结构中组合多个真/假条件。

    2. Arithmetic Operators | 算术运算符

    The usual arithmetic operators are addition, subtraction, multiplication, division, modulus, integer division and exponentiation. In Python they are written +, -, *, /, %, //, **.

    常见的算术运算符包括加、减、乘、除、取模、整除和乘方。在 Python 中它们分别写作 +、-、*、/、%、//、**。

    • + addition 加;- subtraction 减;* multiplication 乘
    • / division 除;% modulus 取模;// integer division 整除;** exponentiation 乘方

    17 % 5 = 2    and    17 // 5 = 3    and    2 ** 3 = 8

    Remember that % gives the remainder after division, while // discards the fractional part and returns an integer in Python.

    请记住,% 给出除法后的余数,而 // 在 Python 中丢弃小数部分并返回整数。


    3. Comparison / Relational Operators | 比较(关系)运算符

    Comparison operators compare two values and return a Boolean result: True or False. They are essential in selection and iteration.

    比较运算符比较两个值并返回布尔结果:True 或 False。它们在选择和迭代中是必不可少的。

    • == means equal to;!= means not equal to. == 表示等于;!= 表示不等于。
    • >, <, >=, <= test order relationships. >、<、>=、<= 测试大小关系。

    In Edexcel pseudocode, the symbols may be written as = or == depending on the context, so always check the question wording.

    在 Edexcel 伪代码中,符号可能根据上下文写作 = 或 ==,因此务必核对题目措辞。


    4. Logical Operators | 逻辑运算符

    Logical operators act on Boolean values. Python uses and, or and not. Many pseudocode specifications show AND, OR, NOT.

    逻辑运算符作用于布尔值。Python 使用 and、or 和 not。许多伪代码规范显示 AND、OR、NOT。

    • and returns True only if both operands are True. and 仅当两个操作数都为 True 时才返回 True。
    • or returns True if at least one operand is True. or 只要有一个操作数为 True 就返回 True。
    • not reverses the Boolean value. not 反转布尔值。

    (age >= 18) and (country == ‘UK’)

    The expression above is True only when both the age condition and the country condition are True.

    上面的表达式仅当年龄条件和国家条件都为 True 时才为 True。


    5. Bitwise Operators | 位运算符

    Bitwise operators work on binary representations of integers. They are less common in A-Level exams, but you may need to trace bit-level operations such as AND, OR, XOR, NOT, left shift and right shift.

    位运算符对整数的二进制表示进行操作。它们在 A-Level 考试中较少出现,但你可能需要追踪位级运算,例如 AND、OR、XOR、NOT、左移和右移。

    • & bitwise AND;| bitwise OR;^ bitwise XOR;~ bitwise NOT
    • << shifts bits left;>> shifts bits right. << 将位向左移;>> 将位向右移。

    Example: 5 & 3 = 1 because 0101 and 0011 produce 0001.

    示例:5 & 3 = 1,因为 0101 与 0011 得到 0001。


    6. Assignment Operators | 赋值运算符

    The basic assignment operator is =. Compound assignment operators combine arithmetic with assignment, which shortens code.

    基本赋值运算符是 =。复合赋值运算符将算术与赋值结合起来,可以缩短代码。

    • x += 5 is equivalent to x = x + 5. x += 5 等价于 x = x + 5。
    • x *= 2 is equivalent to x = x * 2. x *= 2 等价于 x = x * 2。
    • x //= 3 and x %= 3 behave similarly for integer division and remainder. x //= 3 和 x %= 3 分别类似地执行整除和取余。

    7. Membership and Identity Operators | 成员与身份运算符

    Membership operators test whether a value exists in a sequence. Identity operators test whether two references point to the same object in memory.

    成员运算符测试一个值是否存在于序列中。身份运算符测试两个引用是否指向内存中的同一个对象。

    • in returns True if the element is present in a list, string or tuple. in 如果元素存在于列表、字符串或元组中,则返回 True。
    • not in returns True if the element is absent. not in 如果元素不存在,则返回 True。
    • is checks identity; == checks equality of value. is 检查身份;== 检查值的相等性。

    8. Precedence and Associativity | 优先级与结合性

    Operator precedence decides the order in which operations are evaluated. In most languages, brackets have the highest priority, then exponent, then multiplication/division, then addition/subtraction, then comparisons, then logical operators.

    运算符优先级决定了运算的求值顺序。在大多数语言中,括号优先级最高,然后是乘方、乘除、加减,再然后是比较运算,最后是逻辑运算。

    • Parentheses override all default priority rules. 括号覆盖所有默认优先级规则。
    • *, /, //, % are evaluated before + and -. *、/、//、% 在 + 和 – 之前计算。
    • and is evaluated after comparisons but before or in Python. 在 Python 中,and 在比较之后、or 之前计算。

    Example: 3 + 4 * 2 equals 11, not 14.

    示例:3 + 4 * 2 等于 11,而不是 14。


    9. Common Pitfalls in A-Level Exam | A-Level 考试常见易错点

    Students often confuse = and ==, misuse integer division, or ignore short-circuit evaluation in logical expressions.

    学生经常混淆 = 和 ==,误用整除,或忽略逻辑表达式中的短路求值。

    • Using = for comparison in Python causes a syntax error or unintended assignment. 在 Python 中误将 = 用作比较会导致语法错误或意外赋值。
    • In many languages, / gives a real result while // gives integer division in Python. 在许多语言中,/ 给出实数结果,而 Python 中的 // 给出整除。
    • Check whether the question uses pseudocode or Python; operator symbols can differ. 检查题目使用伪代码还是 Python;运算符符号可能不同。

    10. Quick Revision Table | 快速复习表

    Operator Meaning 含义 Example 示例
    + Addition 加 3 + 2 = 5
    % Modulus 取模 7 % 4 = 3
    // Integer division 整除 7 // 4 = 1
    == Equal to 等于 5 == 5 → True
    and Logical AND 逻辑与 True and False → False
    in Membership 成员 ‘a’ in ‘cat’ → True

    Use this table as a quick check before the exam, but always practise tracing full expressions with mixed operators.

    在考试前可以用此表快速自查,但务必练习追踪包含混合运算符的完整表达式。


    Published by TutorHao | Programming Revision Series | aleveler.com

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

  • Object-Oriented Programming (OOP) for Edexcel A-Level Computer Science | 面向对象编程 (OOP) 考点精讲

    📚 Object-Oriented Programming (OOP) for Edexcel A-Level Computer Science | 面向对象编程 (OOP) 考点精讲

    Object-oriented programming (OOP) is a central programming paradigm in the Edexcel A-Level Computer Science specification. It organises code into classes and objects, making programs easier to design, maintain and reuse. This article explains the key OOP concepts you need to master, from classes and objects to inheritance and polymorphism, with exam-focused examples.

    面向对象编程 (OOP) 是 Edexcel A-Level 计算机科学大纲中的核心编程范式。它把代码组织为类和对象,使程序更易于设计、维护和复用。本文讲解你需要掌握的关键 OOP 概念,从类和对象到继承和多态,并提供贴近考试的示例。


    1. Programming Paradigms: Where OOP Fits | 编程范式:OOP 的定位

    Before studying OOP, it is useful to compare it with other paradigms. Procedural programming uses sequences of instructions and functions; functional programming treats computation as evaluation of mathematical functions; OOP models a system as interacting objects. Edexcel questions often ask you to justify choosing an OOP approach.

    在学习 OOP 之前,先与其他范式比较会很有帮助。过程式编程使用指令序列和函数;函数式编程把计算视为数学函数的求值;OOP 则将系统建模为相互交互的对象。Edexcel 考题常要求你说明选择 OOP 方法的理由。

    Paradigm Key idea Typical languages
    Procedural Step-by-step instructions and procedures C, Pascal
    Functional Evaluation of pure functions, no side effects Haskell, Lisp
    Object-oriented Classes, objects, encapsulation, inheritance Java, Python, C++

    The table summarises the three main paradigms. In an exam, if a scenario describes multiple entities such as students, teachers and courses, OOP is usually the natural choice because it binds data and behaviour together in objects.

    表格总结了三种主要范式。在考试中,如果题目描述一个包含多种实体(如学生、教师、课程)的信息系统,OOP 通常是自然的选择,因为它能将数据和行为绑定在对象中。


    2. Classes and Objects | 类与对象

    A class is a blueprint or template that defines the attributes (data) and methods (behaviour) common to a group of objects. An object is a specific instance of a class. For example, a class Car might have attributes such as registration, make and colour, and methods such as accelerate() and brake(). The object myCar = Car(“AB12 CDE”, “Toyota”, “blue”) is one concrete instance.

    类是一个蓝图或模板,定义了一组对象共有的属性(数据)和方法(行为)。对象是类的具体实例。例如,Car 类可以有注册号、品牌和颜色等属性,以及 accelerate() 和 brake() 等方法。对象 myCar = Car(“AB12 CDE”, “Toyota”, “blue”) 就是一个具体实例。

    CLASS Car
      ATTRIBUTES registration, make, colour
      METHODS accelerate(), brake()
    ENDCLASS

    In Edexcel-style pseudocode, class definitions often look like the structure above. The exact syntax is less important than recognising that attributes hold data and methods define behaviour.

    在 Edexcel 风格的伪代码中,类定义通常类似于上述结构。具体语法远不如识别“属性保存数据、方法定义行为”这一点重要。


    3. Attributes and Methods | 属性与方法

    Attributes store the state of an object, while methods define the operations that can be performed on that state. In Edexcel pseudocode, attributes are often declared inside a class and methods are procedures or functions that belong to the class. You should be able to identify which items in a scenario become attributes and which become methods.

    属性存储对象的状态,方法定义可对该状态执行的操作。在 Edexcel 伪代码中,属性通常在类内部声明,方法则是属于类的过程或函数。你应能判断场景中哪些项应成为属性、哪些应成为方法。

    For example, in a bank account scenario, the balance is an attribute because it is data, while deposit() and withdraw() are methods because they change or inspect the balance. A common exam task is to list suitable attributes and methods for a given class.

    例如,在银行账户情境中,余额是属性,因为它是数据;而 deposit() 和 withdraw() 是方法,因为它们会改变或查看余额。常见考题是列出给定类合适的属性和方法。


    4. Encapsulation | 封装

    Encapsulation means hiding the internal state of an object and requiring all interaction to go through methods. This protects data from accidental corruption and allows the internal implementation to change without affecting other parts of the program. In OOP languages, access modifiers such as private and public control visibility.

    封装是指隐藏对象的内部状态,并要求所有交互都通过方法进行。这样可以保护数据免受意外破坏,并允许内部实现更改而不影响程序的其他部分。在面向对象语言中,private 和 public 等访问修饰符控制可见性。

    For Edexcel, you should know that attributes are usually declared private, while selected methods are public. Encapsulation is often tested by asking why direct access to attributes is harmful, or why getter and setter methods are used.

    在 Edexcel 考试中,你应知道属性通常声明为 private,而选定的方法为 public。封装常以“为什么直接访问属性是有害的”或“为什么要使用 getter 和 setter 方法”的形式进行考查。


    5. Inheritance | 继承

    Inheritance allows a class (subclass) to reuse and extend the attributes and methods of another class (superclass). For example, a Car class can inherit from a Vehicle class. This promotes code reuse and models ‘is-a’ relationships. Edexcel exam questions often provide a class diagram and ask you to explain the relationship.

    继承允许一个类(子类)复用并扩展另一个类(父类)的属性和方法。例如,Car 类可以继承自 Vehicle 类。这促进了代码复用,并建模了“是一种”关系。Edexcel 考题常给出类图,要求你解释这种关系。

    In pseudocode, inheritance might be shown as:

    在伪代码中,继承可以表示为:

    CLASS Car INHERITS Vehicle
      EXTRA ATTRIBUTE numberOfDoors
      OVERRIDE METHOD displayDetails()
    ENDCLASS

    The subclass Car automatically has all the features of Vehicle, but can add new features or change existing ones. This is a high-yield exam topic, especially when combined with overriding.

    子类 Car 自动拥有 Vehicle 的所有特征,但可以添加新特征或修改已有特征。这是一个高频率考点,特别是与重写结合时。


    6. Polymorphism | 多态

    Polymorphism means ‘many forms’. It allows the same method name to behave differently depending on the object that calls it. Method overriding is a common form: a subclass provides its own version of a method inherited from the superclass. In a list of Vehicle objects, calling vehicle.display() can produce different output for a Car, Bike or Lorry.

    多态意为“多种形态”。它允许同一个方法名根据调用它的对象不同而表现出不同行为。方法重写是一种常见形式:子类提供其自己版本的方法以覆盖从父类继承的方法。在一个 Vehicle 对象列表中,调用 vehicle.display() 可以针对 Car、Bike 或 Lorry 产生不同输出。

    This is powerful because a single line of code can work with many types of object without knowing their exact class at compile time. Edexcel questions sometimes ask you to describe how polymorphism improves code maintainability.

    这非常强大,因为一行代码可以处理多种类型的对象,而无需在编译时知道其确切类。Edexcel 题目有时会要求你描述多态如何提高代码的可维护性。


    7. Association, Aggregation and Composition | 关联、聚合与组合

    These terms describe relationships between classes. Association is a general ‘uses-a’ relationship. Aggregation is a ‘has-a’ relationship where the contained object can exist independently, such as a Library having Books. Composition is a stronger ‘has-a’ relationship where the part cannot exist without the whole, such as a House having Rooms. Edexcel questions may ask you to distinguish these.

    这些术语描述类之间的关系。关联是通用的“使用”关系。聚合是一种“拥有”关系,其中被包含的对象可以独立存在,例如图书馆拥有图书。组合是一种更强的“拥有”关系,其中部分不能脱离整体存在,例如房子拥有房间。Edexcel 题目可能要求你区分这些关系。

    Useful exam wording: if the contained object is created and destroyed with the owner, it is composition; if it can outlive the owner, it is aggregation. Drawing clear class diagrams with labelled relationships earns marks even if the diagram is not perfect.

    实用的考试措辞:如果被包含对象随所有者一起创建和销毁,则是组合;如果它能比所有者存活更久,则是聚合。即使类图不完美,清晰绘制并标注关系也能得分。


    8. Advantages and Disadvantages of OOP | 面向对象的优缺点

    Advantages include improved modularity, code reuse through inheritance, easier maintenance due to encapsulation, and the ability to model real-world entities naturally. Disadvantages include a steeper learning curve, increased memory overhead, and the risk of overly complex class hierarchies. You should be prepared to evaluate OOP in a given context.

    优点包括更好的模块化、通过继承实现代码复用、因封装而更易维护,以及能够自然地建模现实世界实体。缺点包括学习曲线较陡、内存开销增加,以及类的层次结构可能过于复杂。你应准备好在具体情境中评价 OOP。

    For high-mark questions, avoid simply listing advantages. Instead, link each point to the scenario: for example, encapsulation prevents invalid data in a banking system, while inheritance reduces duplication in a school records system.

    对于高分题,不要只列优点。相反,要把每一点与情境联系起来:例如,封装可以防止银行系统中的无效数据,而继承可以减少学校记录系统中的重复。


    9. Exam-Style Scenario: Modelling a School System | 考试情境:学校系统建模

    Consider a school information system. You might define a Person class with attributes name and dateOfBirth, and method getAge(). Student inherits from Person and adds attributes studentID and tutorGroup; Teacher inherits from Person and adds staffID and subject. This demonstrates inheritance, encapsulation and polymorphism in a single scenario. An exam question could ask you to draw a class diagram or write pseudocode for one method.

    考虑一个学校信息系统。你可以定义 Person 类,其属性为 name 和 dateOfBirth,方法为 getAge()。Student 继承自 Person,新增属性 studentID 和 tutorGroup;Teacher 继承自 Person,新增 staffID 和 subject。这在一个情境中演示了继承、封装和多态。考题可能要求你画出类图或为一个方法编写伪代码。

    In such scenarios, always identify the superclass first, then decide what subclasses add. The ‘is-a’ test helps: a Student is a Person, so inheritance is valid. A Classroom is not a Person, so it should not inherit from Person; instead it may be associated with Person objects.

    在这类情境中,始终先确定父类,再决定子类新增什么。“是一种”测试很有帮助:Student 是 Person,所以继承有效。Classroom 不是 Person,因此不应继承自 Person;相反,它可以与 Person 对象关联。


    10. Common Pitfalls and Revision Tips | 常见误区与复习建议

    A common mistake is confusing a class with an object: a class is the definition, an object is a specific instance. Another pitfall is treating inheritance as a ‘has-a’ relationship, when it should be ‘is-a’. Practise identifying attributes and methods from a passage, and be precise with access modifiers in exam answers. Use past paper scenarios to build speed.

    一个常见错误是混淆类和对象:类是定义,对象是具体实例。另一个误区是把继承当作“拥有”关系,而它应该是“是一种”关系。练习从段落中识别属性和方法,并在考试答案中准确使用访问修饰符。利用历年真题情境提升答题速度。

    When writing pseudocode, do not forget to declare the class, list its attributes, and show method signatures. Even if you cannot write perfect code, structured pseudocode with clear labels will earn method and attribute marks.

    在编写伪代码时,不要忘记声明类、列出其属性并展示方法签名。即使你无法写出完美代码,结构清晰、标签明确的伪代码也能获得方法和属性方面的分数。

    Published by TutorHao | Computer Science Revision Series | aleveler.com

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

  • A-Level Edexcel Programming: Operators and Programming Structures | A-Level Edexcel 编程:运算符与程序结构

    📚 A-Level Edexcel Programming: Operators and Programming Structures | A-Level Edexcel 编程:运算符与程序结构

    Understanding operators and programming structures is essential for success in the Edexcel A-Level Computer Science Paper 2 and the non-exam assessment. This article covers arithmetic, comparison and Boolean operators, precedence rules, and the three core control structures: sequence, selection and iteration.

    理解运算符和程序结构对于在 Edexcel A-Level 计算机科学 Paper 2 及课程作业中取得成功至关重要。本文涵盖算术、比较和布尔运算符、优先级规则,以及三种核心控制结构:顺序、选择和迭代。


    1. Arithmetic Operators and Precedence | 算术运算符与优先级

    In Edexcel pseudocode, arithmetic operators include + addition, subtraction, * multiplication, / division, DIV integer division, MOD remainder and ^ exponentiation. The result of DIV and MOD depends on whole-number operands.

    在 Edexcel 伪代码中,算术运算符包括 + 加法、 减法、* 乘法、/ 除法、DIV 整除、MOD 取余和 ^ 幂运算。DIV 和 MOD 的结果取决于整数操作数。

    Operators are evaluated in a strict order: brackets first, then ^, then * / DIV MOD, and finally + –. For example, 3 + 4 * 2 equals 11 because multiplication happens before addition.

    运算符按严格顺序求值:先括号,然后 ^,接着 * / DIV MOD,最后 + –。例如,3 + 4 * 2 的结果是 11,因为乘法先于加法进行。

    Expression Result
    7 DIV 2 3
    7 MOD 2 1
    2 ^ 3 8
    (2 + 3) * 4 20

    2. Comparison Operators | 比较运算符

    Comparison operators compare two values and return a Boolean result. Edexcel pseudocode uses = for equality, <> for not equal, > for greater than, < for less than, >= for greater than or equal to, and <= for less than or equal to.

    比较运算符用于比较两个值并返回布尔结果。Edexcel 伪代码使用 = 表示等于,<> 表示不等于,> 表示大于,< 表示小于,>= 表示大于或等于,<= 表示小于或等于。

    In Python the equivalents are ==, !=, >, <, >= and <=. Do not confuse the assignment operator <- in pseudocode with the equality sign =.

    在 Python 中等价运算符是 ==!=><>=<=。不要将伪代码中的赋值运算符 <- 与等号 = 混淆。

    5 > 3 → TRUE   |   4 = 4 → TRUE   |   2 <> 2 → FALSE


    3. Boolean Operators | 布尔运算符

    Boolean operators

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

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

  • Operators and Expressions in Programming | 编程中的运算符与表达式

    📚 Operators and Expressions in Programming | 编程中的运算符与表达式

    Operators and expressions are fundamental to writing correct programs in any language. In Edexcel A-Level Computer Science, candidates must be able to use arithmetic, relational, Boolean and assignment operators confidently, and must understand how precedence rules determine the order of evaluation. This article explains each operator category with clear examples, common pitfalls, and exam-style tips.

    运算符和表达式是编写正确程序的基础。在 Edexcel A-Level 计算机科学课程中,考生必须能够自信地使用算术运算符、关系运算符、布尔运算符和赋值运算符,并理解优先级规则如何决定求值顺序。本文通过清晰的示例、常见误区和考试技巧逐一讲解各类运算符。


    1. Arithmetic Operators | 算术运算符

    Arithmetic operators perform mathematical calculations on numeric values. The standard operators include addition (+), subtraction (-), multiplication (*), division (/), integer division (// or DIV), modulo (%), and exponentiation (** or ^ depending on the language).

    算术运算符对数值执行数学计算。标准运算符包括加(+)、减(-)、乘(*)、除(/)、整除(// 或 DIV)、取模(%)和幂运算(** 或 ^,取决于语言)。

    In Python, the expression 7 + 3 * 2 evaluates to 13 because multiplication has higher precedence than addition. The expression (7 + 3) * 2 evaluates to 20, showing how parentheses change the order of calculation.

    在 Python 中,表达式 7 + 3 * 2 的值为 13,因为乘法的优先级高于加法。表达式 (7 + 3) * 2 的值为 20,说明括号如何改变运算顺序。

    • Use * for multiplication and / for real division. | 乘法用 *,实数除法用 /。
    • Use // for integer floor division, e.g. 17 // 5 = 3. | 整数向下取整除法用 //,例如 17 // 5 = 3。
    • Use % for remainder, e.g. 17 % 5 = 2. | 取余用 %,例如 17 % 5 = 2。

    a + b × c ≠ (a + b) × c

    Many exam questions expect you to trace arithmetic expressions step by step. Always write down intermediate results to avoid careless

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

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

  • A-Level Edexcel Programming: Core Constructs and Exam Skills | Edexcel A-Level 编程核心构件与应试技巧

    📚 A-Level Edexcel Programming: Core Constructs and Exam Skills | Edexcel A-Level 编程核心构件与应试技巧

    This guide focuses on the programming skills required for Edexcel A-Level Computer Science. It covers data types, control flow, data structures, algorithms, recursion, object-oriented basics, file handling, testing and exam-style problem solving. Each section gives you the key idea in English followed by a Chinese explanation to support bilingual revision.

    本指南聚焦 Edexcel A-Level 计算机科学所需的编程技能,涵盖数据类型、控制流、数据结构、算法、递归、面向对象基础、文件处理、测试及考试风格的问题求解。每一节先给出英文要点,再配中文解释,便于双语复习。


    1. Computational Thinking and Program Design | 计算思维与程序设计

    Before writing code, decompose the problem into smaller tasks, identify patterns, and generalise repeating steps into loops or functions. Use pseudocode or structured English to plan logic before coding.

    编写代码前,先把问题分解为更小的任务,识别模式,并将重复步骤归纳为循环或函数。使用伪代码或结构化英语在编码前规划逻辑。

    In Edexcel exams, questions often ask you to trace or complete an algorithm, so a clear design reduces errors and saves time. The three key skills are abstraction, decomposition and pattern recognition.

    在 Edexcel 考试中,题目常要求追踪或补全算法,因此清晰的设计能减少错误并节省时间。三项关键技能是抽象、分解和模式识别。


    2. Data Types and Variables | 数据类型与变量

    Choose appropriate data types: integer for whole numbers, real/float for decimals, Boolean for TRUE/FALSE, character for single symbol, and string for text. Declare variables with meaningful names.

    选择合适的数据类型:整数用于整数,实数/浮点数用于小数,布尔型用于 TRUE/FALSE,字符型用于单个符号,字符串用于文本。用有意义的名字声明变量。

    Type casting changes one data type into another, for example integer to string for output. Check that operations do not cause overflow or truncation errors, especially when dividing integers.

    类型转换将一种数据类型变为另一种,例如输出时把整数转为字符串。检查运算是否会导致溢出或截断错误,尤其是整数除法时。

    Constants should be used for fixed values like tax rate or pi, because they make code easier to update and prevent accidental changes.

    常量应用于固定值,如税率或圆周率 pi,因为它们使代码更易于更新并防止意外修改。


    3. Control Structures: Sequence, Selection, Iteration | 控制结构:顺序、选择与迭代

    Sequence means statements run one after another. Selection uses IF, ELSE IF, ELSE, or CASE statements to choose between paths based on conditions.

    顺序意味着语句一条接一条执行。选择使用 IF、ELSE IF、ELSE 或 CASE 语句根据条件在不同路径之间选择。

    Iteration repeats a block of code. Definite iteration uses FOR loops when the number of repeats is known, while indefinite iteration uses WHILE or REPEAT UNTIL when it depends on a condition.

    迭代重复执行一段代码。当重复次数已知时使用 FOR 循环进行确定迭代;当次数取决于条件时使用 WHILE 或 REPEAT UNTIL 进行不确定迭代。

    Nested control structures can solve complex problems such as tables, matrices or searching grids, but keep indentation clear. In pseudocode, use consistent indentation to show the scope of each block.

    嵌套控制结构可以解决表格、矩阵或网格搜索等复杂问题,但缩进必须清晰。在伪代码中,使用一致的缩进来表示每个块的作用域。


    4. Functions, Procedures and Parameters | 函数、过程与参数

    A procedure performs a task without returning a value, while a function returns a value to the caller. Both help to split code into reusable modules.

    过程执行任务但不返回值,函数将值返回给调用者。两者都有助于将代码拆分为可重用模块。

    Parameters pass data into subroutines. Passing by value copies the argument, so changes do not affect the original; passing by reference allows the subroutine to change the original variable.

    参数把数据传入子程序。按值传递会复制实参,因此修改不会影响原变量;按引用传递则允许子程序更改原变量。

    Use local variables inside subroutines to avoid side effects and global variables only when necessary. A function should normally have one clear purpose and a single return point.

    在子程序内部使用局部变量以避免副作用,仅在必要时使用全局变量。函数通常应具有单一明确目的和单一返回点。


    5. Data Structures: Arrays and Records | 数据结构:数组与记录

    A 1D array stores elements of the same data type in contiguous memory, accessed by index. A 2D array is useful for grids or tables.

    一维数组在连续内存中存储相同数据类型的元素,通过索引访问。二维数组适用于网格或表格。

    Records group related data of different types into one structure, for example a student record with name, id and score. In Python, dictionaries or classes can represent records; in pseudocode, use a RECORD … ENDRECORD block.

    记录将不同类型但相关的数据组合成一个结构,例如包含姓名、编号和成绩的学生记录。在 Python 中可以用字典或类表示记录;在伪代码中使用 RECORD … ENDRECORD 块。

    Stacks use Last In First Out (LIFO) and queues use First In First Out (FIFO). These are common abstract data types tested in Edexcel programming questions, often with push, pop, enqueue and dequeue operations.

    栈使用后进先出 (LIFO),队列使用先进先出 (FIFO)。这些是 Edexcel 编程题中常见的抽象数据类型,常涉及 push、pop、enqueue 和 dequeue 操作。


    6. Searching and Sorting Algorithms | 搜索与排序算法

    Linear search checks each element until the target is found; it works on unsorted data and has average time complexity O(n). Binary search repeatedly halves a sorted list, giving O(log n).

    线性搜索逐一检查每个元素直到找到目标;它适用于未排序数据,平均时间复杂度为 O(n)。二分搜索反复将有序列表折半,时间复杂度为 O(log n)。

    Bubble sort passes through adjacent pairs to swap out-of-order elements; insertion sort builds a sorted part by inserting each next element; merge sort divides and merges. Use trace tables to show each pass.

    冒泡排序遍历相邻元素对并交换顺序错误的元素;插入排序通过插入下一个元素逐步构建已排序部分;归并排序先分治再合并。使用追踪表展示每一趟。

    Algorithm | 算法 Best | 最好 Average | 平均 Worst | 最坏
    Linear search | 线性搜索 O(1) O(n) O(n)
    Binary search | 二分搜索 O(1) O(log n) O(log n)
    Bubble sort | 冒泡排序 O(n) O(n²) O(n²)
    Merge sort | 归并排序 O(n log n) O(n log n) O(n log n)

    7. Recursion and Problem Solving | 递归与问题求解

    A recursive routine calls itself with a smaller input. It must have a base case to stop and a recursive case that moves toward the base case.

    递归例程用更小的输入调用自身。它必须有停止的基本情形,以及向基本情形推进的递归情形。

    Example: factorial(n) = n × factorial(n − 1), with factorial(0) = 1. Trace trees show each call and return value, helping you avoid missing the base case.

    示例:factorial(n) = n × factorial(n − 1),且 factorial(0) = 1。追踪树展示每次调用和返回值,帮助你避免遗漏基本情形。

    Recursion uses the call stack, so too many calls can cause stack overflow; iterative solutions are often more memory-efficient. In Edexcel pseudocode, recursive functions are written like normal functions but contain a call to themselves.

    递归使用调用栈,因此调用过多会导致栈溢出;迭代方案通常更节省内存。在 Edexcel 伪代码中,递归函数写法类似普通函数,但包含对自身的调用。


    8. Object-Oriented Programming Basics | 面向对象编程基础

    A class is a blueprint; an object is an instance. Attributes store data and methods define behaviour. Encapsulation hides internal details and exposes only a public interface.

    类是蓝图;对象是实例。属性存储数据,方法定义行为。封装隐藏内部细节,只暴露公共接口。

    Inheritance allows a subclass to reuse and extend a parent class. Polymorphism lets different objects respond to the same method call in their own way.

    继承允许子类复用并扩展父类。多态让不同对象以各自的方式响应同一方法调用。

    In Edexcel A-Level, OOP questions usually ask you to identify classes, attributes, methods and relationships, not to write full class syntax. However, you should know the terms constructor, getter and setter.

    在 Edexcel A-Level 中,面向对象题目通常要求识别类、属性、方法和关系,而不要求写出完整类语法。但你应了解构造方法、getter 和 setter 等术语。


    9. File Handling and Validation | 文件处理与验证

    Common file operations are open, read, write, append and close. Always close files to free system resources.

    常见文件操作包括打开、读取、写入、追加和关闭。始终关闭文件以释放系统资源。

    Validation checks input before processing: presence, range, type, length and format. Verification such as double entry checks that data is entered correctly.

    验证在处理前检查输入:存在性、范围、类型、长度和格式。核实如双重输入用于检查数据输入正确。

    Use exception handling to manage file not found, wrong type or end-of-file conditions without crashing. In pseudocode, this can be shown with TRY … EXCEPT or OPEN FILE … IF NOT EXISTS.

    使用异常处理来管理文件不存在、类型错误或文件结束等情况而不崩溃。在伪代码中,可以用 TRY … EXCEPT 或 OPEN FILE … IF NOT EXISTS 表示。


    10. Testing, Debugging and Exam Technique | 测试、调试与应试技巧

    Create a test plan with normal, boundary and erroneous data. For example, if a mark must be 0–100, test 50, 0, 100, −1 and 101.

    创建包含正常、边界和错误数据的测试计划。例如,若分数必须在 0–100 之间,则测试 50、0、100、−1 和 101。

    Dry run algorithms with trace tables tracking variables and outputs step by step. This is a key Edexcel exam skill because many questions ask you to complete a trace table or identify the final output.

    使用追踪表逐步记录变量和输出,对算法进行干运行。这是 Edexcel 考试的关键技能,因为许多题目要求你补全追踪表或确定最终输出。

    Read questions carefully: if asked to write an algorithm, use clear pseudocode; if asked to identify errors, compare the code with the required logic. Check that your solution handles all valid inputs and at least one invalid input.

    仔细读题:若要求编写算法,使用清晰的伪代码;若要求找出错误,则将代码与所需逻辑进行比较。检查你的解决方案是否处理了所有有效输入以及至少一种无效输入。

    Published by TutorHao | Programming Revision Series | aleveler.com

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

  • Operators, Expressions and Precedence in Programming | 编程中的运算符、表达式与优先级

    📚 Operators, Expressions and Precedence in Programming | 编程中的运算符、表达式与优先级

    In Edexcel A-Level Computer Science, understanding operators and how expressions are evaluated is essential for writing correct pseudocode and for tracing algorithms. This article covers the operators you need to know, their precedence, and common exam-style pitfalls.

    在 Edexcel A-Level 计算机科学中,理解运算符以及表达式如何求值,对于编写正确的伪代码和追踪算法至关重要。本文介绍你需要掌握的运算符、它们的优先级以及考试中常见的易错点。

    1. Operators as Building Blocks | 运算符是构建模块

    Operators are special symbols or keywords that tell the computer to perform a specific operation on one or more values. In A-Level programming, you must be able to use arithmetic, relational, Boolean, string, and assignment operators in pseudocode and in a chosen high-level language.

    运算符是告诉计算机对一个或多个值执行特定操作的特殊符号或关键字。在 A-Level 编程中,你必须能够在伪代码和所选高级语言中使用算术、关系、布尔、字符串和赋值运算符。

    • Arithmetic operators – perform calculations. | 算术运算符 – 执行计算。
    • Relational operators – compare values. | 关系运算符 – 比较值。
    • Boolean operators – combine truth values. | 布尔运算符 – 组合真值。
    • String operators – manipulate text. | 字符串运算符 – 处理文本。
    • Assignment operators – store values. | 赋值运算符 – 存储值。

    Understanding how these operators interact in an expression is a core skill for tracing and writing algorithms.

    理解这些运算符在表达式中如何相互作用,是追踪和编写算法的核心技能。


    2. Arithmetic Operators | 算术运算符

    Arithmetic operators are used for mathematical calculations. In Edexcel pseudocode, the usual symbols are +, -, *, /, DIV and MOD. DIV returns the whole-number quotient, while MOD returns the remainder after whole-number division.

    算术运算符用于数学计算。在 Edexcel 伪代码中,常用符号是 +、-、*、/、DIV 和 MOD。DIV 返回整数商,而 MOD 返回整数除法后的余数。

    Operator Meaning Example Result
    + Addition 加 7 + 2 9
    Subtraction 减 7 – 2 5
    * Multiplication 乘

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

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

  • Object-Oriented Programming (OOP) for Edexcel A-Level Programming | Edexcel A-Level 编程:面向对象编程核心概念

    📚 Object-Oriented Programming (OOP) for Edexcel A-Level Programming | Edexcel A-Level 编程:面向对象编程核心概念

    Object-oriented programming (OOP) is a central paradigm in the Edexcel A-Level Programming specification. It models real-world entities as objects that combine data and behaviour. This article covers the key OOP concepts you must understand for the exam, including classes, objects, encapsulation, inheritance and polymorphism.

    面向对象编程(OOP)是 Edexcel A-Level 编程规范中的核心范式。它将现实世界实体建模为结合数据与行为的对象。本文涵盖考试必须掌握的关键 OOP 概念,包括类、对象、封装、继承和多态。


    1. What is Object-Oriented Programming? | 什么是面向对象编程?

    Object-oriented programming is a programming paradigm based on the concept of objects. Each object contains data, known as attributes, and code, known as methods. The main aim is to structure programs so that they are easier to design, debug and maintain.

    面向对象编程是一种基于对象概念的编程范式。每个对象包含称为属性的数据和称为方法的代码。其主要目标是构建程序,使其更易于设计、调试和维护。

    In Edexcel A-Level exams, you may be asked to explain why OOP is suitable for large software projects. Key reasons include modularity, reusability and the ability to hide internal details from other parts of the program.

    在 Edexcel A-Level 考试中,你可能会被要求解释为什么 OOP 适合大型软件项目。关键原因包括模块化、可重用性以及向程序其他部分隐藏内部细节的能力。

    Example: A ‘BankAccount’ object can hold a balance attribute and methods such as deposit() and withdraw(). This keeps related data and operations together.

    示例:一个 ‘BankAccount’ 对象可以保存余额属性以及 deposit() 和 withdraw() 等方法。这样可将相关数据和操作组织在一起。


    2. Classes and Objects | 类与对象

    A class is a template or blueprint that defines the attributes and methods common to a group of objects. An object is a specific instance of a class created at runtime. The distinction between class and object is frequently examined.

    类是定义一组对象共有属性和方法的模板或蓝图。对象是类在运行时创建的具体实例。类与对象的区别是常考内容。

    In Python, you define a class using the ‘class’ keyword. Creating an object uses the class name followed by parentheses. The following code shows a simple Dog class and two Dog objects.

    在 Python 中,使用 ‘class’ 关键字定义类。创建对象时使用类名后跟括号。以下代码展示了一个简单的 Dog 类和两个 Dog 对象。

    class Dog:
      def __init__(self, name):
        self.name = name

    dog1 = Dog(‘Rex’)
    dog2 = Dog(‘Bella’)

    Here ‘Dog’ is the class and ‘dog1’ and ‘dog2’ are objects or instances of the class. Each object has its own copy of the ‘name’ attribute.

    这里 ‘Dog’ 是类,’dog1′ 和 ‘dog2’ 是对象或类的实例。每个对象都有自己的 ‘name’ 属性副本。


    3. Attributes and Methods | 属性与方法

    Attributes are variables that belong to an object and store its state. Methods are functions defined inside a class that describe the behaviours of the object. In exam questions, you must be able to identify attributes and methods from class diagrams or code.

    属性是属于对象的变量,用于存储其状态。方法是在类内部定义的函数,描述对象的行为。在考试题中,你必须能够从类图或代码中识别属性和方法。

    For example, a Student class may have attributes such as name, age and grade, and methods such as enrol() and calculateAverage(). Methods often use the ‘self’ parameter in Python to refer to the current object.

    例如,Student 类可能有 name、age 和 grade 等属性,以及 enrol() 和 calculateAverage() 等方法。在 Python 中,方法常使用 ‘self’ 参数来引用当前对象。

    Attributes can be public or private. Private attributes are indicated by a double underscore prefix in Python, but the concept of visibility is more important than syntax in Edexcel exams.

    属性可以是公有或私有。在 Python 中,

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

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