Edexcel GCSE Computer Science Programming Language Subset (1CP2): the Python you need
GCSE Computer Science
Start today's paperPaper resets in
Formula sheet
The card below opens today's Computer Science paper with the language reference in the drawer, so you practise with the Python the paper uses. The tables follow, in our own layout. This guide follows Version 6 of the PLS, so check Pearson's site for the version for your series before you rely on anything here.
GCSE Computer Science
Operators
| Operator | Meaning | Example |
|---|---|---|
| / * ** | divide, multiply, raise to a power | 2 ** 3 is 8 |
| + - | add, subtract | a + b |
| // | integer division | 23 // 5 is 4 |
| % | modulus (remainder) | 23 % 5 is 3 |
| == != > >= < <= | relational tests | x != 7 |
| and or not | Boolean tests | not (a < b) |
Data types
Conversion uses int(), str(), float(), bool() or list(). Constants are named in all capitals by convention.
| Type | In the subset | Note |
|---|---|---|
| integer | int | whole numbers |
| real | float | numbers with a decimal part |
| Boolean | bool | True or False |
| character and string | str | a sequence of characters, indexed from 0 |
| array and record | list | indexed from 0, up to two dimensions |
Selection and loops
Blocks are shown by indentation. The stop value of range() is not included, and start and step are optional.
| Construct | Form | Example |
|---|---|---|
| if | if condition: ... | if x > 3: |
| else | else: ... | else: |
| elif | elif condition: ... | elif x == 3: |
| while | while condition: ... | while total < 100: |
| for over a structure | for item in structure: ... | for name in names: |
| for over a range | for i in range(start, stop, step): ... | for i in range(2, 11, 4): |
Subprograms, input and output
The subset supports comma separated value text files.
| Construct | Form | Example |
|---|---|---|
| procedure | def name(parameters): ... | def greet(name): |
| function | def name(parameters): ... return (value) | return (total) |
| output | print(item) | print("Hello") |
| input | input(prompt) | name = input("Name? ") |
| read a file | open(name, "r") readline() readlines() | f = open("data.csv", "r") |
| write a file | open(name, "w") or "a" write() writelines() | f.write("text") |
| close a file | close() | f.close() |
Built-in subprograms
| Item | What it does | Example |
|---|---|---|
| len(object) | length of a string or list | len("keyboard") is 8 |
| chr(n) and ord(c) | character from code, code from character | ord("a") is 97 |
| range(start, stop, step) | generates numbers, stop not included | range(2, 11, 4) |
| round(x, n) | rounds x to n decimal places, with the 0.5 rule | round(3.14159, 2) is 3.14 |
| int() float() str() bool() | convert between types | int("16") is 16 |
Lists and strings
The subset also supports isalpha(), isalnum(), isdigit(), isupper() and islower(), string slicing such as name[0:2], and "=" * 10 to repeat a string.
| Item | What it does | Example |
|---|---|---|
| list.append(item) | add to the end | names.append("Ada") |
| list.insert(index, item) | insert before the item at index | names.insert(0, "Bo") |
| del list[index] | remove the item at index | del names[2] |
| string.find(sub) | first position, or -1 | text.find("a") |
| string.index(sub) | first position, or an exception | text.index("a") |
| string.upper() .lower() | change case | text.upper() |
| string.replace(s1, s2) | replace every s1 with s2 | text.replace("a", "o") |
| string.split(char) | split into a list | line.split(",") |
| string.strip(char) | remove char from the ends | text.strip(" ") |
| string.format(values) | format values into placeholders | "{:>6.2f}".format(x) |
Library modules
A module must be imported before use, for example import random. The subset also has a turtle module for graphics.
| Item | What it does | Example |
|---|---|---|
| random.randint(a, b) | random integer from a to b inclusive | random.randint(1, 6) |
| random.random() | random float from 0.0 to 1.0 | random.random() |
| math.ceil(x) math.floor(x) | round up, round down | math.floor(2.7) is 2 |
| math.sqrt(x) math.pi | square root, and pi | math.sqrt(49) is 7.0 |
| time.sleep(seconds) | pause the program | time.sleep(2) |
Reading the Python subset
Python shows a block by indenting it, so the layout is part of the code. Trace this short program:
total = 0
for n in range(1, 6):
total = total + n * n
print(total)range(1, 6) gives 1, 2, 3, 4 and 5, because the stop value is not included. The total adds 1, 4, 9, 16 and 25, so the program prints 55.
| n | n * n | total |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 4 | 5 |
| 3 | 9 | 14 |
| 4 | 16 | 30 |
| 5 | 25 | 55 |
Dividing, strings and a function
23 // 5 is 4 and 23 % 5 is 3, because 23 = 4 × 5 + 3. range(2, 11, 4) gives 2, 6 and 10. This function returns a value:
def is_even(n):
if n % 2 == 0:
return (True)
else:
return (False)
print(is_even(17))17 % 2 is 1, so the condition is false and the program prints False.
What the subset does not give you
- Which structure to use. It lists while and for loops. Choosing the right one for a question is yours to do.
- Algorithms. Searching, sorting and the other algorithms are not written out. You need to know how they work.
- Python beyond the subset. Pearson will not set tasks beyond the PLS, but you may use more if your solution is valid.
- Ragged data structures. The PLS does not support them: each record in a list has the same number of fields.
- Errors. It does not say what a syntax error or a logic error looks like, so learn to spot both.
How to use the subset in the exam
- Read the whole program once before you trace it.
- Make a table with a column for each variable and one row for each pass of a loop.
- Remember that strings and lists start at index 0.
- Check the stop value of range(): it is not included.
- Keep your indentation consistent, because it shows the blocks.
The subset and other boards' languages
AQA uses its own pseudo-code and OCR uses its own Exam Reference Language, with different keywords. Use the one your board names: see our AQA pseudo-code and OCR Exam Reference Language guides. For the boards, papers and grade boundaries, see our GCSE Computer Science guide.
Use the sheet with today's paper
Uni-Sine publishes a free daily paper for GCSE Computer Science. It is a short timed paper of 8 questions worth 25 to 35 marks, not a full Edexcel paper, and it is not written by Pearson. Open the reference, set a timer and write your trace table at the top of each answer. After marking, look at any question where you used the wrong loop or the wrong operator.
Common mistakes
- Off by one with range(). range(1, 6) stops at 5, because the stop value is not included.
- Mixing up // and %. // is the whole number quotient and % is the remainder.
- Using = to compare. = assigns, and == compares.
- Forgetting the colon. if, elif, else, while, for and def lines all end with a colon.
- Counting from 1. Strings and lists start at index 0.
- Forgetting to convert input. input() returns text, so use int() or float() before arithmetic.
Exam answers
The answers and a worked mark scheme come with today's paper once it is marked. Sit the paper with the sheet open beside you, mark it, and the worked answers show which line of the sheet each question wanted. We do not publish official or past paper answers.
Common questions
What is the Edexcel Programming Language Subset?
Does the PLS limit what Python I can use?
Which version of Python does Edexcel use?
What is the difference between // and % in the PLS?
Does the PLS include turtle graphics?
Revision cards
Say the answer first, then flip the card to check it.
Where to go next
- Solve it
Code Editor
Write and run code right in your browser
Open the tool - Learn it
Programming Languages
Compiled vs interpreted, paradigms and the evolution of how we talk to machines
Start the course - Test it
GCSE Computer Science
A new exam-style paper every day, with instant marking and a mark scheme
Start today's paper