01 / Programming and robust programsEvery board
What is a variable?
- AA named store for a value that can change
- BA value that never changes while code runs
- CA block of code that returns a value
- DA set of values stored under one name
Show the answer
Answer: A A named store for a value that can change
A variable is a named location in memory that holds a value, and the value can change as the program runs, like a score going up.
Checked against ocr.org.uk
02 / Programming and robust programsEvery board
const VAT = 0.2
A named value that cannot change while the program runs is a:
- Avariable
- Bconstant
- Cparameter
- Drecord
Show the answer
Answer: B constant
A constant gets its value once and cannot be changed by mistake while the program runs. A name like VAT also makes the code easier to read, and if the rate changes you edit one line.
Checked against ocr.org.uk
03 / Programming and robust programsEvery board
Giving a variable a value, as in score = 0, is called:
- Acomparison
- Bconcatenation
- Citeration
- Dassignment
Show the answer
Answer: D assignment
Assignment stores a value in a variable. OCR’s reference language and Python use = (score = 0), while AQA pseudo-code uses an arrow (score ← 0). Checking whether two values are equal is a comparison.
Checked against ocr.org.uk
04 / Programming and robust programsOCR, Edexcel and Eduqas
In OCR’s reference language and in Python, what does == do?
- AChecks whether two values are equal
- BChecks whether two values are different
- CJoins two strings together
- DGives a variable a new value
Show the answer
Answer: A Checks whether two values are equal
A single = assigns a value; a double == compares two values and gives True or False. != means not equal to. Mixing up = and == is a common slip in conditions.
Checked against ocr.org.uk
05 / Programming and robust programsEvery board
Which data type best suits a person’s age in whole years?
- ACharacter
- BInteger
- CReal
- DBoolean
Show the answer
Answer: B Integer
Integers are whole numbers, so they suit counts and ages. Real numbers (called float in Python) have a decimal part, so they suit prices and measurements. Choosing the right type lets you do arithmetic correctly.
Checked against cdn.sanity.io
06 / Programming and robust programsEvery board
A club stores whether each member has paid, as True or False. Which data type fits?
- ACharacter
- BInteger
- CReal
- DBoolean
Show the answer
Answer: D Boolean
A Boolean holds one of only two values, True or False. It suits yes or no facts, such as paid or not paid, and it is what every condition in an IF statement or a loop works out to.
Checked against ocr.org.uk
07 / Programming and robust programsEvery board
Which data type should store a phone number such as 07700 900123?
- AInteger
- BReal
- CString
- DBoolean
Show the answer
Answer: C String
A phone number starts with 0, has a space, and you never do arithmetic with it. Stored as an integer, the leading zero would be lost, so a string is the right choice.
Checked against ocr.org.uk
08 / Programming and robust programsEvery board
A single grade letter such as B is best stored as which data type?
- ACharacter
- BInteger
- CReal
- DBoolean
Show the answer
Answer: A Character
A character holds exactly one letter, digit or symbol. A string of one character would also work, but character is the closest fit; neither a number type nor a Boolean can hold a letter.
Checked against cdn.sanity.io
09 / Programming and robust programsEvery board
Changing a value from one data type to another, such as a string to an integer, is called:
- Acasting
- Bvalidation
- Cconcatenation
- Diteration
Show the answer
Answer: A casting
Casting converts data to another type: int(“42”) turns the string “42” into the number 42, and str(42) does the reverse. AQA calls these string conversion operations.
Checked against ocr.org.uk
10 / Programming and robust programsEvery board
age = input(“Enter your age”)
nextYear = age + 1
Why does the second line cause an error in Python?
- Ainput() can only be used inside a loop
- Binput() gives a string, so age must be cast to an integer
- CThe number 1 must always be written inside quotes as a string
- DVariable names cannot contain capital letters
Show the answer
Answer: B input() gives a string, so age must be cast to an integer
Input from the keyboard arrives as a string, even when it looks like a number. Casting it with int() turns it into an integer that can be used in arithmetic. Forgetting this is a very common error.
Checked against docs.python.org
11 / Programming and robust programsEvery board
Joining two strings end to end, such as “Good” and “bye”, is called:
- Acasting
- Bconcatenation
- Citeration
- Dslicing
Show the answer
Answer: B concatenation
Concatenation joins strings, so “Good” + “bye” gives “Goodbye”. It uses + in OCR’s reference language, AQA pseudo-code and Python. No space is added for you, so a space must be put inside the quotes.
Checked against ocr.org.uk
12 / Programming and robust programsEvery board
Taking out part of a string, such as the first three letters of a word, gives a:
- Asubstring
- Bconstant
- Ccast
- Dconcatenation
Show the answer
Answer: A substring
A substring is part of a string. OCR’s reference language has .substring(start, count), .left() and .right(); AQA pseudo-code has SUBSTRING; Python uses slices such as word[0:3].
Checked against ocr.org.uk
13 / Programming and robust programsEvery board
Why might code convert a user’s answer to upper case before checking it?
- ATo turn the answer into a number
- BBecause strings must be in capitals
- CSo “yes”, “Yes” and “YES” all match
- DTo make the answer use less memory
Show the answer
Answer: C So “yes”, “Yes” and “YES” all match
Converting to one case, with .upper in OCR’s reference language or .upper() in Python, means the check works however the user typed the answer. It is a small piece of defensive design.
Checked against ocr.org.uk
14 / Programming and robust programsEvery board
A string function such as len() in Python or .length in OCR’s reference language returns:
- Athe number of separate words that the string contains
- Bthe first character of the string
- Cthe string in capital letters
- Dthe number of characters in the string
Show the answer
Answer: D the number of characters in the string
The length counts every character, including spaces and punctuation. It is used in length checks, for example to make sure a password has at least eight characters.
Checked against ocr.org.uk
15 / Programming and robust programsEvery board
Code that runs one line after another, in order, uses which construct?
- AIteration
- BSelection
- CCasting
- DSequence
Show the answer
Answer: D Sequence
Programs are built from three constructs: sequence (steps in order), selection (choosing a path with IF or switch) and iteration (repeating with a loop). Edexcel and Eduqas also call loops repetition.
Checked against ocr.org.uk
16 / Programming and robust programsEvery board
for i = 1 to 10
print(i)
next i
What kind of loop is this?
- AA nested IF statement
- BAn infinite loop
- CA condition-controlled loop
- DA count-controlled loop
Show the answer
Answer: D A count-controlled loop
A for loop is count-controlled: it repeats a set number of times, here 10, with i counting from 1 to 10 (both ends included in OCR’s reference language). AQA calls this definite iteration.
Checked against ocr.org.uk
17 / Programming and robust programsEvery board
answer = “”
while answer != “Paris”
answer = input(“Capital of France?”)
endwhile
What kind of loop is this?
- AA switch statement
- BA condition-controlled loop
- CA count-controlled loop
- DA nested function
Show the answer
Answer: B A condition-controlled loop
A while loop repeats as long as its condition is True, so it suits repeating an unknown number of times. Here it keeps asking until the answer is Paris. AQA calls this indefinite iteration.
Checked against ocr.org.uk
18 / Programming and robust programsEvery board
An IF statement placed inside a loop is an example of:
- Acasting
- Bconcatenation
- Cdecomposition
- Dnesting
Show the answer
Answer: D nesting
Nesting means putting one construct inside another, such as a loop inside a loop or an IF statement inside a loop. Indenting each level shows clearly which code belongs where.
Checked against cdn.sanity.io
19 / Programming and robust programsEvery board
Which operator gives the remainder after one whole number is divided by another?
- AOR
- BAND
- CDIV
- DMOD
Show the answer
Answer: D MOD
DIV gives the whole number of times one number goes into another and MOD gives what is left: 11 DIV 2 is 5 and 11 MOD 2 is 1. In Python they are written // and %.
Checked against cdn.sanity.io
20 / Programming and robust programsEvery board
Which condition is True only when the whole number n is even?
- An / 2 == 1
- Bn MOD 2 == 0
- Cn MOD 2 == 1
- Dn DIV 2 == 0
Show the answer
Answer: B n MOD 2 == 0
An even number leaves no remainder when divided by 2, so n MOD 2 == 0 tests for even. MOD is often used for checks like this, such as doing something on every third turn.
Checked against ocr.org.uk
21 / Programming and robust programsEvery board
if age >= 11 AND <= 16 then
This condition should accept ages 11 to 16. Which is the correct way to write it?
- Aage >= 12 AND age <= 15
- Bage > 16 AND age < 11
- Cage >= 11 OR age <= 16
- Dage >= 11 AND age <= 16
Show the answer
Answer: D age >= 11 AND age <= 16
Each side of AND or OR needs a full comparison with the variable named again. Writing AND <= 16 on its own is a very common exam mistake, and using OR would let every age through.
Checked against ocr.org.uk
22 / Programming and robust programsEvery board
What is an array?
- AA single value that can change
- BA named value that never changes
- CA group of fields about one item
- DA set of values stored under one name
Show the answer
Answer: D A set of values stored under one name
An array holds many values under one name, each found by its index. Because the index is a number, a loop can visit every item, which is far shorter than writing out 30 separate variables.
Checked against cdn.sanity.io
23 / Programming and robust programsEvery board
Which is best stored in a two-dimensional array?
- AA True or False flag
- BOne customer’s name
- CA single high score
- DA seating plan of rows and seats
Show the answer
Answer: D A seating plan of rows and seats
A 2D array is like a table or grid, so each item needs two indexes, such as seats[2, 5] in OCR’s reference language. It suits grids such as a seating plan, a game board or a table of results.
Checked against ocr.org.uk
24 / Programming and robust programsEvery board
One car: make “Ford”, model “Fiesta”, price 9500.00, doors 5
Data grouped like this, as several named fields about one item, is a:
- Aconstant
- Brecord
- CBoolean
- Dprocedure
Show the answer
Answer: B record
A record groups the details of one thing, like one car or one pupil, into named fields. The fields can be different types: make is a string, price is real and doors is an integer. In a database table, one record is one row.
Checked against cdn.sanity.io
25 / Programming and robust programsEvery board
What is the difference between a function and a procedure?
- AA function returns a value; a procedure does not
- BA procedure returns a value; a function does not
- CA function cannot take parameters
- DA procedure can only be used once
Show the answer
Answer: A A function returns a value; a procedure does not
Both are named blocks of code, called subroutines or sub programs, that you call by name. A function sends a value back with return; a procedure carries out its steps without returning a value.
Checked against qualifications.pearson.com
26 / Programming and robust programsEvery board
function area(width, height)
return width * height
endfunction
What are width and height in this function?
- AParameters
- BReturn values
- CConstants
- DGlobal variables
Show the answer
Answer: A Parameters
Parameters are the names in brackets that receive the values passed in when the function is called. Here width gets 3 and height gets 4, and return sends 12 back to the calling code to be used or stored.
Checked against ocr.org.uk
27 / Programming and robust programsEvery board
A task says a function must return a total. What should its last line before endfunction be?
- Atotal = 0
- Btotal = input()
- Cprint(total)
- Dreturn total
Show the answer
Answer: D return total
Do what the question asks: return passes a value back, while print only shows it on screen. A function should use the values passed in as parameters, not ask for them again. Examiners often see both mistakes.
Checked against ocr.org.uk
28 / Programming and robust programsEvery board
A variable declared inside a subroutine is a:
- Aglobal variable
- Blocal variable
- Cconstant
- Drecord
Show the answer
Answer: B local variable
A local variable exists only while its subroutine is running and can only be used inside it. This stops other parts of the program changing it by accident, and different subroutines can reuse the same names.
Checked against cdn.sanity.io
29 / Programming and robust programsEvery board
Which is a benefit of splitting a program into subroutines?
- AVariables no longer need names
- BEach one can be written and tested on its own
- CThe program always runs faster
- DThe program no longer needs testing
Show the answer
Answer: B Each one can be written and tested on its own
A subroutine can be called many times instead of repeating code, tested on its own, and shared out among a team. This structured approach makes programs shorter, easier to read and easier to maintain.
Checked against cdn.sanity.io
30 / Programming and robust programsEvery board
Which is a sensible use of random numbers?
- AStoring a pupil’s date of birth
- BRolling a dice in a board game
- CSorting a list of names
- DChecking a password is correct
Show the answer
Answer: B Rolling a dice in a board game
Random numbers make games and simulations unpredictable. In each of these forms both end values can come up, so a dice roll uses 1 and 6.
Checked against docs.python.org
31 / Programming and robust programsEvery board
What is input validation?
- AChecking that data entered is sensible before it is used
- BConfirming who the user is
- CMaking sure the data is definitely correct
- DTesting the finished code with normal, boundary and erroneous data
Show the answer
Answer: A Checking that data entered is sensible before it is used
Validation checks input against rules, such as a range or a length, and rejects data that breaks them. It cannot tell whether sensible data is true: a wrong but believable date of birth will still pass.
Checked against ocr.org.uk
32 / Programming and robust programsEvery board
Making sure an age is between 11 and 18 is a:
- Aformat check
- Brange check
- Cpresence check
- Dlength check
Show the answer
Answer: B range check
A range check tests limits, a presence check makes sure something was entered, a length check counts characters, and a format (or pattern) check tests the arrangement of characters. A type check makes sure data is the right data type.
Checked against qualifications.pearson.com
33 / Programming and robust programsEvery board
What is authentication?
- ATesting code with sample data
- BConfirming the identity of a user
- CTranslating code into machine code
- DChecking input is sensible
Show the answer
Answer: B Confirming the identity of a user
Authentication makes sure a user is who they say they are, most simply with a username and password checked against stored details. Validation is different: it checks that data is sensible.
Checked against ocr.org.uk
34 / Programming and robust programsEvery board
Which of these makes code easier to maintain?
- AWriting everything without indentation
- BUsing meaningful variable names
- CRemoving all comments
- DUsing single letters for every variable
Show the answer
Answer: B Using meaningful variable names
Maintainable code is easy for someone else, or you later, to read and change. Meaningful names, comments, indentation and subroutines all help. Comments are ignored by the translator, so they do not change what the code does.
Checked against ocr.org.uk
35 / Programming and robust programsEvery board
What is the main purpose of testing?
- ATo make the code shorter
- BTo translate the code into machine code
- CTo prove that the code will never, ever contain a single error
- DTo find errors and check the code meets its requirements
Show the answer
Answer: D To find errors and check the code meets its requirements
Testing tries to find errors so they can be fixed, and checks the code does what it is meant to do. It cannot prove there are no errors at all, only that the tests passed.
Checked against ocr.org.uk
36 / Programming and robust programsEvery board
A quiz accepts scores from 0 to 20.
Which is normal test data for this rule?
- A-3
- B12
- C21
- Dten
Show the answer
Answer: B 12
Normal data is sensible data that should be accepted, like 12. Boundary data sits at the edge of what is allowed, like 0 or 20; AQA also counts -1 and 21, just outside. Erroneous data, like the word “ten”, should be rejected. Eduqas says typical and extreme.
Checked against cdn.sanity.io
37 / Programming and robust programsEvery board
In a test plan, why is the expected result written down before the test is run?
- ASo the test does not need to be run
- BSo the data passes validation
- CSo the actual result can be compared with it
- DSo the code runs faster
Show the answer
Answer: C So the actual result can be compared with it
A test plan lists each test, the test data, its type (normal, boundary and so on) and the expected result. Writing the expected result first means you can tell whether the actual result is right.
Checked against ocr.org.uk
38 / Programming and robust programsEvery board
print(“Hello”
What kind of error is in this line?
- AA rounding error
- BA runtime error
- CA syntax error
- DA logic error
Show the answer
Answer: C A syntax error
A syntax error breaks the grammar rules of the language, here a missing closing bracket, so the code cannot be translated or run. The translator reports it, usually with a line number.
Checked against ocr.org.uk
39 / Programming and robust programsEvery board
if age > 18 then
print(“Adult”)
endif
This code should print Adult for anyone aged 18 or over. What kind of error does it have?
- AA rounding error
- BA runtime error
- CA syntax error
- DA logic error
Show the answer
Answer: D A logic error
The code runs, but an 18 year old is not called an adult, because > means strictly greater than. Code that runs but gives the wrong result has a logic error; here >= is needed.
Checked against ocr.org.uk
40 / Programming and robust programsEvery board
Why are logic errors often harder to find than syntax errors?
- AThe code still runs, so no error message appears
- BThe translator deliberately hides them from the programmer
- CThey only happen on some computers
- DThey make the computer switch off
Show the answer
Answer: A The code still runs, so no error message appears
A translator spots syntax errors because they break the language rules. A logic error is valid code doing the wrong thing, so it only shows up through testing, trace tables or careful checking of the output.
Checked against cdn.sanity.io