Third Form Computer Science — enter the class password
Work through each section, then test yourself with the questions below.
The exam writes code in OCR Exam Reference Language. It looks different from Python but does the same things. You need to be able to read and understand OCR pseudocode, but you will write your answers in Python.
then, elseif (one word), and endif. Python uses :, elif, and indentation only.
Both print: 0, 1, 2, 3, 4. But notice: OCR includes the end number (to 4 means up to and including 4). Python excludes it (range(0, 5) stops before 5).
An array stores multiple values in one variable. Every item has an index starting at 0.
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Value | Ali | Ben | Cat | Dev | Eve |
names[0] → Ali names[4] → Eve names.length → 5
from 0 to (array.length - 1).
scores[2]?scores.length?
scores[2] = 12 (index 2 is the third item — indexing starts at 0)scores.length = 5 (there are 5 items in the array)
colours.
range(len(colours)) gives indices 0 to length-1 automatically.
for i = 0 to names.length cause a problem?
names.length = 5, so it would try to access names[5] which is out of range. You must use names.length - 1.
| Symbol | Meaning | Example |
|---|---|---|
== | Equal to | if x == 5 |
!= | Not equal to | if x != 0 |
> | Greater than | if age > 17 |
< | Less than | if temp < 0 |
>= | Greater than or equal to | if score >= 50 |
<= | Less than or equal to | if count <= 10 |
= stores a value. Two equals signs == checks if values are equal. Mixing these up is the most common mistake.
| OCR | Python | Meaning | Example | Result |
|---|---|---|---|---|
+ | + | Addition | 3 + 4 | 7 |
- | - | Subtraction | 10 - 3 | 7 |
* | * | Multiplication | 5 * 4 | 20 |
/ | / | Division | 10 / 3 | 3.33... |
DIV | // | Integer division | 10 DIV 3 | 3 |
MOD | % | Remainder | 10 MOD 3 | 1 |
200 DIV 60 = 3 hours, 200 MOD 60 = 20 minutes → 3h 20m
| Operator | What it means | True when... |
|---|---|---|
AND | Both must be true | True AND True → True |
OR | At least one true | False OR False → False, rest → True |
NOT | Flips the result | NOT True → False |
17 DIV 517 MOD 5200 MOD 60
= and ==?
= is assignment — it stores a value in a variable (e.g. x = 5 sets x to 5).== is comparison — it checks if two values are equal (e.g. if x == 5 checks if x is 5).
and/or are lowercase in Python.
Set counter to 0. Loop through array. Check each item. Add 1 if it matches. Print counter after the loop.
OCR PseudocodeGet all inputs. Combine conditions with AND and OR using brackets. Output for both outcomes.
OCR PseudocodeFollow these steps: Input → Edge case → Calculate → Convert (DIV/MOD) → Output
OCR — Battery charger exampletemps are greater than 30.
// is integer division, % is remainder.
if x = 5= to compareif x == 5== to comparefor i = 0 to names.lengthfor i = 0 to (names.length - 1)if A AND B OR Cif A AND (B OR C)endif, next, or endwhileif needs endif, every for needs nextscore = input("Score: ") then doing mathsscore = int(input("Score: "))== for comparisons (not =)?endif, next, endwhile)