GCSE Computer Science revision
Programming
Variables, selection, iteration and functions in Python.
What you will learn
- Variables and data types
- Sequence, selection, iteration
- Functions and procedures
- Arrays and lists
- String manipulation
Variables and data types
Variables store data. Each has a type: integer, real/float, Boolean, character, string.
- Integer: whole numbers (e.g. 5)
- Float: numbers with decimals (e.g. 3.14)
- String: text in quotes (e.g. 'hello')
- Boolean: True or False
Sequence, selection, iteration
Every program is built from sequence (doing things in order), selection (making choices) and iteration (repeating).
- Sequence: instructions run in order
- Selection: if/else makes decisions
- Iteration: for and while loops repeat
- These are the three building blocks of programming
Functions and procedures
A function is a reusable block of code that returns a value; a procedure does a job but returns nothing.
- Functions can take parameters
- Functions return a value; procedures do not
- They make code reusable and modular
- Defining a function: def name(parameters):
Arrays and lists
Lists store multiple values in one variable. You can read, add and remove items by their index.
- Indices start at 0
- Append adds an item to the end
- Lists can hold mixed types in Python
- Loops can iterate over list items
String manipulation
Strings can be sliced, joined and searched. Common operations include finding length, substrings and concatenation.
- len() gives the length
- Concatenation joins strings with +
- Slicing extracts part of a string
- Upper and lower change case
Worked answers
1. Which data type stores True or False?
Answer: Boolean
Why: Booleans have only two possible values: True or False.
Wrong options to rule out: Integer; String; Float
2. An if/else statement is an example of…
Answer: Selection
Why: Selection means the program chooses between paths.
Wrong options to rule out: Sequence; Iteration; Decomposition
3. A function differs from a procedure because it…
Answer: Returns a value
Why: Functions return a result; procedures just perform an action.
Wrong options to rule out: Runs faster; Uses no variables; Cannot be reused
Practice questions
Answer from memory first. Pick an option to check it and read the explanation.
1. In Python, the first item in a list has index…
2. Which loop runs a set number of times?
3. Concatenation means…
4. Which is the correct way to define a function in Python?
5. A while loop keeps running while a…