< Back to all GCSE Cheat Sheets
Latest update: 24/01/2024 13:17.
Last content addition: 23/08/2023 21:50
Looking to ace your exams with easy-to-access, free 1:1 advice from exam survivors? Connect with fellow students, developers, educators and professionals in the Baguette Brigaders Discord server who can answer all your questions and give you tips and tricks! Plus, you can opt to receive automatic notifications whenever new content is added here!
Please use your class notes, if you have any, as well as this, to aid your revision. I’ve tried to make it as packed full of only the most useful stuff as possible which will come up in the exam. This covers 15 pages of specification content and 210 hours of lesson time, consolidated into one place, so it might not cover everything in 100% detail, but I have written more for the things which people may find more confusing. If there are any errors then please let me know immediately. I have tried my best to make it as easy as possible to understand and get a grade 9😉
This cheat sheet covers all of specification for: J277/02: Computational thinking, algorithms and programming. Check the Cheat Sheets page to see Paper 1 individually.
From OCR:
J277/02: This component will assess:
• 2.1 Algorithms
• 2.2 Programming fundamentals
• 2.3 Producing robust programs
• 2.4 Boolean logic
• 2.5 Programming languages and Integrated Development Environments
You need to know how to create, interpret the results of, complete and refine algorithms in these languages. If you can’t code Python, you can use an online tool like Replit (where you can code wiith friends at the same time too!) or use an IDE like IDLE or VS Code and just start coding something random. You will find my examples at the bottom for inspiration.
There are 3 words to describe ‘computational thinking’:
Sometimes I might get annoyed if you don’t think algorithmically…
It is only when a problem is decomposed and abstracted, that the creation of the solution can begin.
An algorithm is a step-by-step set of instructions used to solve a problem. Before designing an algorithm, it must be decomposed into its inputs, outputs and the order of instructions, as well as if any decisions need to be made.
Algorithms are made in three different ways: pseudocode, flowcharts and Python (or another high-level language/OCR reference language).
x = x + 10
x > y
. Then there would be 2 lines coming from this, one for yes and one for no.
Make sure you know this. Credit BBC
Example use. Credit BBC
Advantages of using flowcharts include the fact that they show a step-by-step method of how to solve a program, which can be easily written. Disadvantages of flowcharts include that they may be time-consuming to make and not easily drawn.
The advantages of using pseudocode (looks like real code but won’t execute) include it acts as the foundation for transcribing it into an actual programming language like Python, and is easy to understand with an English-like syntax, like Python, making it easy for non-programmers as well, like Python. Errors in the design will not affect the program as it is obvious what the intended result is, and if there is an obvious error this can be easily changed.
Disadvantages include that it can be harder to see how a program flows with indentation, and is just more time-consuming to make than a flowchart, so you might as well use Python for that.
Pseudocode example:
while answer_inputted != 'valorant'
answer_inputted = input ("What is the worst game?")
if answer_inputted == "valorant" then
print("Correct! you got it right.")
else
print("Wrong")
endif
endwhile
It’s relatively easy to tell what this ‘code’ does:
while
the answer_inputted
is not 'valorant'
.answer_inputted
to the outcome of the input
if
answer_inputted
is 'valorant'
prints
a responseelse
so this will be used when the previous statement is not true
(if the answer_inputted
is not ‘valorant’)print
wrongA trace table is a table used to show how values in variables change throughout instructions occurring.
In the columns goes the variable name. In the rows, the instruction number is written. Below the variable names, in the table, are the expected values of what each instruction does.
A logic error occurs if the expected value on paper does not equal the received value when executed by the program.
They enable a programmer to compare what the value of each variable should be against what a program actually produces. Where the two differ is the point in the program where a logic error has occurred.
From Bitesize.
The simplest method of searching through a dataset. It gets the length of a dataset and sets it counter to 0. It looks at the position of its counter and sees if it matches the search. If not, the counter is incremented by 1 and the process is repeated
Linear searches work on unordered lists. On ordered lists, they will take a long time if the value to search for is a large number.
Binary search is used on a dataset of pre-ordered numbers. It works by:
Note: rounding applies. If there are 7 items in the list, the midpoint would be 3.5. In this case, the search would start from 4.
Binary searches are much more efficient than linear searches, especially on large datasets.
In an ordered list of every number from 0 to 100, a linear search would take 99 steps to find the value 99. A binary search would only require seven steps.
https://www.bbc.co.uk/bitesize/guides/zjdkw6f/revision/4
Very simplified version:
Bitesize’s version
Large data sets are better with merge sorts as they are more efficient.
https://www.bbc.co.uk/bitesize/guides/zjdkw6f/revision/5
More efficient than bubble sort, but less complex and efficient than a merge sort
Bitesize’s version
Insertion sorts work best when used with smaller data sets.
https://www.bbc.co.uk/bitesize/guides/zjdkw6f/revision/6
x = input("enter string: ")
print("output")
x
to the data, which is 2
, an integer.Sequence refers to the order in which the code is executed.
Selection is a part of the code that is run, or if
statements. When these statements are encountered, it ‘selects’ which part to run!
Iteration is a loop. There are count and condition-controlled loops.
if x > 10:
will run until the value of x
is greater than 10
.True
or False
; these will run until this value is changed. For example, if x == True:
will run the code until the value ofx
is no longer equal to True
.There are comparison and arithmetic operators. (They will give the boolean value of True
if their criteria are met)
==
!=
True
when the value it is comparing against is NOT the first value.<
True
when the value in front of it is less than the value after it. if x < 3
means if x is less than 3.<=
True
when the value in front of it is less OR equal to the value after it.>
True
when the value in front of it is more than the value after it. if x > 3
means if x is greater than 3.>=
True
when the value in front of it is more OR equal to the value after it.+
-
*
/
MOD
DIV
^
Casting is a method used to convert between these data types. For example, if you want to compare a user’s input to a value, you must change it to an integer first. The way to do this is by using:
x = input("how much cake do you want from to 10? >>")
if int(x) > 5:
print("you really want cake lol")
You use int(x) to change x to an integer.
Or, str() for strings, or float() for floating point data.
You can turn the above into two lines by using this:
if int(input("how much cake do you want from to 10? >>")) > 5:
print("you really want cake lol")
There’s a lot of content here, so make sure you are comfortable with it.
Not manipulating surds, or abusing strings, but just messing about with the string instead.
The length of a string can be obtained by doing len(string)
, where string
is a variable holding a string value.
You can also get the characters at a specific point in a string. If x
= ‘Baguette’, then x[3]
would be ‘u’. Remember that 0 is your first value in a list/array.
To get the characters from positions 0 and 3 (not included), the syntax is this: x[0:3]
= would be ‘Bag’. This is known as ‘slicing’.
You can also manipulate the casing of everything in a string. If x
= ‘Baguette’, then x = x.upper()
would result in x
being ‘BAGUETTE’. Likewise, x.lower()
would be ‘baguette’.
Finally, concatenation is joining two strings together.
If one = "Baguette"
and two = "Brigaders"
, then one + " " + two
would print Baguette Brigaders
.
If you feel comfortable with f-strings then you could get the same by using
print(f"{one.lower()} {two.upper()}")
to output ‘baguette BRIGADERS’.
Arrays (interchangeable with lists honestly) store lots of stuff and are denoted by their square brackets, like [4, 5, 3, 6, 9]
or with strings as ["Yes", "No", "Baguettes", "Beans", "Haram"]
. They can be accessed by the sting name and location in the list. If the above list with strings is called random_words
, then to print the word ‘Baguettes’ I would call print(random_words[2])
.
2D arrays take this principle and make it more complicated. Basically, this means there is an array inside an array.
list_of_cars_and_prices = [["beans car", "bozo car", "fresh car"], [20, 30, 55]]
Notice how inside one list, there are actually 2 smaller lists? This is a 2D array. To get the value of ‘55’ from the second array, we do print(list_of_cars_and_prices[1][2]
. This gets the third value from the second array, inside the list called ‘list_of_cars_and_prices’. This can be used to store values next to each other.
To change the value of an item in an array/list, do:
list_name[index] = "thing_to_change_it_to"
A procedure performs a task, whereas a function produces information.
Parameters can be invoked into both functions and procedures. For example, beans(number_of_beans)
will result in the function or procedure using the invoked value of number_of_beans
to perform a calculation.
Functions return a value. You can assign a value to a variable and set this value to the result of a function, like x = beans()
, where beans
is a defined function. It could return a number or string or any data type.
Programming languages have their own built-in functions and procedures. When you type
print("text")
, you are actually passing in yourtext
as a parameter used to display something on your screen! User-defined functions and procedures are the ones that the user creates.
writing:
file1 = open("file.txt")
x = file1.write("Hello! This is a file!")
file1.close()
Reading back the contents:
file1 = open("file.txt")
x = file1.read()
file1.close()
print(x)
>>> Hello! This is a file!
It’s best practice to always do file.close()
to avoid file corruption.
Global variables can be accessed by every subroutine at all times. Present in memory during execution. They aren’t good because if it gets maliciously changed, or changes unintentionally, then it will affect the entire code and every subroutine. Also, it can use a lot of memory if many variables are used at once - normal in big programs and games. The scope of these is the entire program.
Local variables are declared in one subroutine or function. The value of this is only held in memory whilst that specific part of the code (i.e. the subroutine) is being executed. Therefore, it’s more efficient. The scope of these is the sub-program of declaration.
Parameter passing - allows the values of local variables within the main program to be passed to sub-programs without the need to use global variables. The value of these variables (or a copy of the value of these variables) is passed as a parameter to and from sub-programs as necessary.
You can read more about the scope, lifespan and implications of memory scopes on the A Level Cheat Sheet !
SQL is a programming language used for interrogating a database.
Data can be retrieved using the commands SELECT, FROM
and WHERE
*
stands for wildcard, which means all records.
from the iBaguette emails database:
SELECT * FROM "Users" WHERE "Email Address" LIKE "admin" OR "draggie"
would retrieve:
ID | User | Surname | Email Address |
---|---|---|---|
1 | Draggie | 306 | draggie@ibaguette.com |
6 | Admin | Beans | admin@ibaguette.com |
7 | Draggie1 | 306 | admin@ibaguette.com |
You must import random
at the start of the program for this to work (it is a module).
random.randint(lower_bound, upper_bound)
is used to generate a random number between bounds. Assign this to a variable and you have your randomly generated number.
A program must be able to handle all likely input values, not just the intended one. If valid data is inputted which might affect functionality, for example entering -10 to an age question, then this will produce logic errors. To accommodate this, there can be a range of things added to a program to ensure these do not occur.
if age > 10 AND age < 100
. This is an example of input validationpassword = input("enter password")
and using double equals to check if it matches a previously defined variable, or even decrypted from an external file.Code written must also be maintainable in the future. There are several ways of ensuring this.
In BaguetteBot, whenever someone generates coins in a Discord server, one subroutine takes care of this, instead of being defined how to exactly add a coin whenever someone asks for their balance, joins voice chat, sends a message, etc.
x
doesn’t really tell you what it does, whereas value_inputted
will. (I’m very guilty of this!)#
, """
or //
, depending on the language. The first two are for Pythion.Testing is used to make sure there are no bugs or unexpected events when the code is run. You don’t want to send your code to a client if it doesn’t work!
Logic errors result in the program still executing, but producing unexpected results.
Syntax errors are errors which break the grammatical rules of the programming language and stop it from being run/translated into machine code.
Il existe deux exemples de tests :
Normal test data is data which should be accepted by a program, without causing errors
Boundary test data is data of the correct type which is on the very edge of being valid. For example, in the statement if x > 10
, the boundary would be 10.
Invalid test data is data of the correct data type which should be rejected by a computer system. This could be like if an age is -100 years old.
Erroneous test data is data of the incorrect data type which should be rejected by a computer system. This could be entering a name instead of an age.
You need to know how to identify suitable test data for a scenario, and how to create and complete a test plan. By putting in ‘erroneous’, ‘boundary’ and ‘valid’ during iterative testing and final testing, this will get you full marks.
Ahhh… logic diagrams and truth tables. My worst enemy. There’s always a tricksy little 1 or 0 that I always put in the wrong place and there goes my full marks for the test. Grrrr!
Your AND, OR and NOT gates.
You must be able to follow the lines in a truth table, and the interactions these have at these gates.
AND gate outputs
OR gate outputs
Deez NOTs
You don’t have to know this lol
There are two categories of programming language: high and low-level languages.
Assembly code, although is a low-level language, is not quite machine code. Machine code is what everything must be translated into to be executed.
Taken from here
A compiler parses the source code once, saving the results as a binary file, and translating it. An interpreter reads the source code line by line and converts it to executable binary while executing.
Compiled code runs faster, as they have already been translated. If the code has no logic or syntax errors and does not need to be debugged, compiled code is always better. It optimises code as well, allowing it to take up less memory. For example, comments are removed when generating compiled code. However, compiled code may also only be on the hardware and OS it is targeted to. You can’t run an EXE file on your phone without an IDE.
Interpreted code is slower, as the CPU must wait for every line to be translated, but has the potential to run on multiple kinds of hardware, running different operating systems. It simply executes code, without saving a machine code version. They require less memory also as they do not translate the entire file.
Interpreters can be built with a REPL, or a Read Execute Print Loop. Hence the name of the coding platform, Replit.
The IDE (integrated development environment) has a wide range of tools to help programmers develop programs. These include:
You can also write about:
That’s it! Go get a grade 9! Of course, you need to do some of your own programming, so a few examples are below for you to have a go at.
while
loop and the age must be between 10 and 100 years old. When done, return to the original function and print the age in a piece of text. Maximum 25 lines.My example.
Download Python / txt
import random
x = input("Enter your highest number to guess.\n\n>>> ")
target = random.randint(1, int(x))
guessed = False
while guessed == False:
guess = int(input("Enter your guess: "))
if guess == target:
print("You got it! Well done!")
guessed = True
else:
how_far_off = target - guess
print("Unfortunately you are", how_far_off, "points away. Sorry!")
My example.
Download Python / txt
def getAge():
validAnswer = False
while validAnswer == False:
age = int(input("Enter your age:\n\n>>> "))
if age > 10 and age < 100:
print("Valid age entered. You may now play.")
return age
else:
print("Enter a valid age.")
def menu():
print("Welcome to the gambling arena.")
print("To play, you must enter your age.")
age = getAge()
print("Ok! You are", age, "years old. You can now play!")
menu()
Here’s my example.
I also used “f-strings” and more to make it look more complicated.
Download Python / txt
cars_data = [["among car", "sussy car", "beans car", "spelunked car", "supressed (s)car"], [10, 20, 40, 20, 10], []]
coins = 100
while coins > 10:
print(f"You have {coins} coins available to spend!")
print(f"The cars available to buy are {cars_data[0]}")
x = int(input("Enter the chronological number of the car you want to buy.\n>>> "))
x = x - 1
newcar_cost = cars_data[1][x]
if coins - newcar_cost >= 0:
if "Bought" not in cars_data[0][x]:
coins = coins - newcar_cost
cars_data[2].append(cars_data[0][x])
print(f"you just bought {cars_data[0][x]}")
cars_data[0][x] = f"{cars_data[0][x]} (Bought)"
else:
print("You already own this car.")
else:
print(f"You cannot afford any more cars! You have: {cars_data[2]}")
Come back to the GCSE Computer Science Cheat Sheet page soon, and I’ll have created 50+ free coding exercises to get you coding, just like the ones above, for a huge variety of different levels, complete with tutorials and exemplar responses.
You’ve made it to the end!
Good luck with your exams!
Feel free to share this Cheat Sheet with friends, family and teachers.
Made with 💕 by Draggie