0% found this document useful (0 votes)
9 views4 pages

Paper 1 Cheat Sheet

This cheat sheet covers key concepts in structured programming, including data types, relational operators, and robust programming techniques. It explains programming languages, data structures, iteration types, and string handling, along with input/output and file handling in Python. Additionally, it highlights the importance of subroutines, parameters, and the distinction between procedures and functions.

Uploaded by

Angi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Paper 1 Cheat Sheet

This cheat sheet covers key concepts in structured programming, including data types, relational operators, and robust programming techniques. It explains programming languages, data structures, iteration types, and string handling, along with input/output and file handling in Python. Additionally, it highlights the importance of subroutines, parameters, and the distinction between procedures and functions.

Uploaded by

Angi S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Programming - AQA Computer Science Cheat Sheet

by [deleted] via cheatography.com/56036/cs/15020/

Structured Progra​mming Maths (in Python)

The structured approach to progra​mming means that code is more Operation Example
logical and readable, making it easier to debug and maintain. It also Addition Pseudocode: 11 + 2 = 13
makes it more efficient. The most important part of this approach is Python example: 11 + 2 = 13
modula​rised progra​mming , which is the use of subrou​tines. Other
Subtra​ction Pseudocode: 11 - 2 = 9
components include detailed code annotation and clearly named
Python example: 11 - 2 = 9
variables.
Multip​lic​ation Pseudocode: 11 x 2 = 22
Data Types Python example: 11 * 2 = 22

Data Definition Example(s) Real or Float Division Pseudocode: 11 DIV 2 = 5.5

Type Python example: 11 / 2 = 5.5

Integer A whole, positive number. 134 Integer Division Pseudocode: 11 // 2 = 5


Python example: 11 // 2 = 5
Real or Any number, including decimals and -19.21
Float negatives. Remainder of a Division Pseudocode: 11 MOD 2 = 1
Python example: 11 % 2 = 1
Character A letter, number, space, etc. that can be @
typed, in accordance with ASCII or
Selection
Unicode.
String A string of charac​ters. "​Hello, Selection is when a program makes a decision, usually taking the
world!​" form of IF statement.
For example (pseud​ocode):
Boolean Logical values based on binary (1 and 0). True, False
IF x = TRUE THEN
Data Type: A specific type of value (and variable) that must be ​PRINT "​Yes."
handled in a certain way.
ELSE
​PRINT "​No."​
Relational Operators

Symbol Meaning Variables


= equal to What is the 'scope' of a variable?
≠ not equal to The part of the program where a variable is valid and access​ible.
< less than
Why is it important to give variables distin​ctive identi​fiers?
> greater than
This makes debugging and mainte​nance easier, as it is easier for
≤ less than or equal to the programmer to understand the purpose of the variable.
≥ greater than or equal to

By [deleted] Published 8th May, 2018. Sponsored by Readable.com


cheatography.com/deleted- Last updated 8th May, 2018. Measure your website readability!
56036/ Page 1 of 4. https://readable.com
Programming - AQA Computer Science Cheat Sheet
by [deleted] via cheatography.com/56036/cs/15020/

Robust & Secure Progra​mming Progra​mming Languages (cont)

There are two main ways to make programs more robust. Machine Code vs Assembly Language
Firstly, using data validation, which is most easily done using an Both machine code and assembly language are low-level
IF/ELI​F/ELSE statement or a TRY/EXCEPT statement. This makes languages, with assembly code having a 1:1 corres​pon​dance with
sure the data inputted by the user is valid, preventing a runtime error. machine code. However, each type of processor has its own
Secondly, authen​tic​ation . This primarily takes the form of passwords. specific machine code instru​ction set, which is expressed in
However, testing is also key in ensuring that a program is robust. A binary. Assembly language is generally used for software for
programmer must test typical (normal), boundary (extreme), and embedded systems and for contro​lling specific hardware
erroneous data to guarantee that the program deals with data compon​ents.
correctly.
Transl​ation

Data Structures All programs written in high-level languages or assembly


language must be translated into machine code before they can
What are data structures?
be run.
A data structure is a way of storing data.
Interp​retors, compilers, and assemblers
What is an array?
An assembler translates assembly language to machine code. An
An array is a collection of related data (of the same data type). interp​retator translates high-level languages into machine code. It
Each piece of data is an element with a specific index. They may does so line-b​y-line, which makes debugging easier. A compiler
also be called 'lists'. also translates high-level languages to machine code, but it
What is a two dimens​ional array? translates the whle program before running . While the compli​‐
ation process is slow, the machine code can then be stored and
Essent​ially, a 2D array is just an array made of arrays. They can
run quickly in future.
be thought of as a matrix. Possible uses include a bitmap for an
image.
Types of Iteration
What is a record?
What is definite iteration?
A record is very similar to an array, except multiple data types can
be stored together. There is a set number of iterat​ions.

Example of definite iteration (Python):


Progra​mming Languages for i in range(5):
High-Level Languages vs Low-Level Languages x = x + 1

Most programs are initially written in high-level progra​mming What is indefinite iteration?
languages (e.g. Python) because these are more like human
There is not set number of iterat​ions, as it is instead dependent
languages, meaning that they are easier for progra​mmers to
on when a certain condition becomes true.
unders​tand, code in, and debug. They are said to provide a
Example of indefinite iteration (Python):
'higher level of abstra​ction' from machine code. Low-level
langages are very different and much more difficult. Despite this, while x < 5:
progra​mming in machine code allows for the optimi​sation of code x = x + 1
and avoid code having to be transl​ated.
What is nested iteration?
A loop (itera​tion) within a loop.

Examples of nested iteration (Python):


while n == False:
for i in range(5):
x = x + 1

Note that selection statements can also be nested.

By [deleted] Published 8th May, 2018. Sponsored by Readable.com


cheatography.com/deleted- Last updated 8th May, 2018. Measure your website readability!
56036/ Page 2 of 4. https://readable.com
Programming - AQA Computer Science Cheat Sheet
by [deleted] via cheatography.com/56036/cs/15020/

Boolean Logic Gates String Handling (cont)

POSITION() print(​str​‐ To find the position (similar to an index)


ing​_to​_se​‐ of a specific character in a string. If the
arc​h.f​ind​‐ character appears multiple times, only
("a")) the first instance will be returned.
SUBSTR​‐ To create a substring. The first
SOURCE: www.cs.hm​c.e​du/​csf​ora​ll/​Com​put​erO​rga​niz​ati​on/​Com​put​‐
ING​(In​tExp, paramter indicates the start of the
erO​rga​niz​ati​on.html
IntExp, substring, the second the end, and the
StringExp) final parameter being the string itself.
Subrou​tines
+ firstname To concat​enate (join) two strings
What is are subrou​tines?
+ together.
Named ‘out of line’ blocks of code that are executed (called) by lastname
writing its name in a program statement.
ORD() ASCIIcode To convert a character to character
Advantages of subrou​tines = ord('a') code.
1. It makes programs more efficient, because blocks of code can CHR() character To convert character code to character.
be reused. = chr(97)
2. It means that code is easier to debug, because it is shorter.
STR() str(bi​rth​‐ To convert a string to an integer.
Parameters date)
A value that is passed to a subrou​tine. These may also be called INT() int(ph​one​‐ To convert an integer to a string.
'argum​ents'. number)

Procedures vs Functions Note that the pseudocode is not set. Different people will write their
Both take parame​ters, but functions return a value, whereas psuedocode differ​ently.
procedures don't.

Local Variables
Subrou​tines can declare local variables, the scope of which is
limited to the subrou​tine. Using local variables is good practice
because it allows the program to be simpler. Global variables, on
the other hand, make a program much more complex, as they
may change freque​ntly.

String Handling

Pseudocode Python Example Purpose


LEN() Find the length of a string.

By [deleted] Published 8th May, 2018. Sponsored by Readable.com


cheatography.com/deleted- Last updated 8th May, 2018. Measure your website readability!
56036/ Page 3 of 4. https://readable.com
Programming - AQA Computer Science Cheat Sheet
by [deleted] via cheatography.com/56036/cs/15020/

Input, Output, and File Handling (Python)

In Python, the input() function allows a program to receive data from


the user. Similarly, print() allows the program to output inform​ation to
the user.
File handling is slightly more complex. A typical file-o​pening
statement would take this format:
file_o​bject = open(“​fil​ename”, “mode”)
The 'mode' could be 'read' ('r' - allows access only), 'write' ('w' -
allows access and editing), or 'appen​ding' ('a' - allows inform​ation to
be added to the end of the file.
Once the program has finished using a file, the "​fil​ena​me".c​lose()
function should be used, as this frees up resources.

Random Number Generation

In Python, random number generation requires the import​ation of the


RANDOM module. For example:
import random
x = random.ra​ndi​nt(​0,10)
print(x)

By [deleted] Published 8th May, 2018. Sponsored by Readable.com


cheatography.com/deleted- Last updated 8th May, 2018. Measure your website readability!
56036/ Page 4 of 4. https://readable.com

You might also like