2.2.1 Programming Fundamentals
In this lesson, we will cover the essential concepts required to build a strong foundation in programming. We will explore the use of variables, constants, operators, inputs, outputs, assignments, and the three basic programming constructs to control the flow of a program: sequence, selection, and iteration (count-controlled and condition-controlled loops). Additionally, we will delve into common arithmetic and boolean operators, as well as the required comparison operators.
Programming Terms
Variables and constants are fundamental building blocks in programming. They allow data to be stored, accessed, and used by a program.
- Variables: Variables are used to store data in a program. They have a name and a data type (e.g., integer, float, string) and can be updated or modified throughout the program's execution. Data types are covered in Lesson 2.2.2 Data Types.
- Constants: Constants are fixed values that remain the same throughout the program's execution. They are assigned a value once and cannot be changed during runtime.
| Concept | OCR Exam-Style Pseudocode | Python |
|---|---|---|
| Variable | x = 3 message = “Hello World!” |
|
| Constant | const VAT = 0.2 | VAT = 0.2 |
Assignments, operators, inputs, and outputs form the core of how programs process and communicate data.
- Assignments: Assignments involve storing values in variables. The assignment operator (=) is used to assign values to variables.
- Operators: Operators are symbols used to perform operations on variables and constants. Arithmetic operators perform mathematical operations (addition, subtraction, multiplication, division, etc.), while Boolean operators perform logical operations (AND, OR, NOT).
- Inputs: Inputs are values provided to the program during runtime, allowing users to interact with the program and provide data or information.
- Outputs: Outputs are the results produced by the program after performing calculations or processing the provided inputs.
| Operator | OCR Exam-Style Pseudocode | Python | Explanation |
|---|---|---|---|
| Addition | + | Adds two values together. | |
| Subtraction | - | Subtracts the right operand from the left operand. | |
| Multiplication | * | Multiplies two values. | |
| Division | / | Divides the left operand by the right operand. | |
| Modulus (remainder) | MOD | % | Calculates the remainder of the division of the left operand by the right operand. |
| Quotient (whole number division) | DIV | // | Calculates the integer quotient of the division of the left operand by the right operand. |
| Exponentiation (e.g. 2³) | ^ | ** | Raises the left operand to the power of the right operand. |
| Operator | OCR Exam-Style Pseudocode | Python | Explanation |
|---|---|---|---|
| AND | && | Returns true if both conditions on the left and right sides of the operator are true. | |
| OR | || | Returns true if at least one of the conditions on the left and right sides of the operator is true. | |
| NOT | ! | Reverses the logical state of a condition. If the condition is true, NOT makes it false, and if the condition is false, NOT makes it true. | |
| Operator | OCR Exam-Style Pseudocode | Python | Explanation |
|---|---|---|---|
| Equal to | == | Checks if two values are equal. | |
| Not equal to | != | Checks if two values are not equal. | |
| Less than | < | Checks if the value on the left is less than the value on the right. | |
| Less than or equal to | <= | Checks if the value on the left is less than or equal to the value on the right. | |
| Greater than | > | Checks if the value on the left is greater than the value on the right. | |
| Greater than or equal to | >= | Checks if the value on the left is greater than or equal to the value on the right. | |
Only the modulus, quotient, and exponentiation operators differ in the OCR pseudocode.Note
