Show Working
Open the app

GCSE Computer Science · Algorithms and programmingOCR, AQA, Edexcel and Eduqas

Programming and robust programs: GCSE questions with answers

40 GCSE Computer Science questions on this topic. Pick your answer, then tap to see if you were right and why. Every one comes from the Show Working Computer Science bank and is checked against the source named under it.

Quiz yourself: 40 questions 1 exam question

01 / Quiz yourselfTry it, then tap to check

Programming and robust programs questions to try

Choose your answer before you open it. Then read why, so it sticks.

01 / Programming and robust programsEvery board

What is a variable?

  1. AA named store for a value that can change
  2. BA value that never changes while code runs
  3. CA block of code that returns a value
  4. 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:

  1. Avariable
  2. Bconstant
  3. Cparameter
  4. 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:

  1. Acomparison
  2. Bconcatenation
  3. Citeration
  4. 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?

  1. AChecks whether two values are equal
  2. BChecks whether two values are different
  3. CJoins two strings together
  4. 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?

  1. ACharacter
  2. BInteger
  3. CReal
  4. 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?

  1. ACharacter
  2. BInteger
  3. CReal
  4. 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?

  1. AInteger
  2. BReal
  3. CString
  4. 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?

  1. ACharacter
  2. BInteger
  3. CReal
  4. 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:

  1. Acasting
  2. Bvalidation
  3. Cconcatenation
  4. 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?

  1. Ainput() can only be used inside a loop
  2. Binput() gives a string, so age must be cast to an integer
  3. CThe number 1 must always be written inside quotes as a string
  4. 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:

  1. Acasting
  2. Bconcatenation
  3. Citeration
  4. 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:

  1. Asubstring
  2. Bconstant
  3. Ccast
  4. 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?

  1. ATo turn the answer into a number
  2. BBecause strings must be in capitals
  3. CSo “yes”, “Yes” and “YES” all match
  4. 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:

  1. Athe number of separate words that the string contains
  2. Bthe first character of the string
  3. Cthe string in capital letters
  4. 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?

  1. AIteration
  2. BSelection
  3. CCasting
  4. 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?

  1. AA nested IF statement
  2. BAn infinite loop
  3. CA condition-controlled loop
  4. 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?

  1. AA switch statement
  2. BA condition-controlled loop
  3. CA count-controlled loop
  4. 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:

  1. Acasting
  2. Bconcatenation
  3. Cdecomposition
  4. 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?

  1. AOR
  2. BAND
  3. CDIV
  4. 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?

  1. An / 2 == 1
  2. Bn MOD 2 == 0
  3. Cn MOD 2 == 1
  4. 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?

  1. Aage >= 12 AND age <= 15
  2. Bage > 16 AND age < 11
  3. Cage >= 11 OR age <= 16
  4. 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?

  1. AA single value that can change
  2. BA named value that never changes
  3. CA group of fields about one item
  4. 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?

  1. AA True or False flag
  2. BOne customer’s name
  3. CA single high score
  4. 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:

  1. Aconstant
  2. Brecord
  3. CBoolean
  4. 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?

  1. AA function returns a value; a procedure does not
  2. BA procedure returns a value; a function does not
  3. CA function cannot take parameters
  4. 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?

  1. AParameters
  2. BReturn values
  3. CConstants
  4. 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?

  1. Atotal = 0
  2. Btotal = input()
  3. Cprint(total)
  4. 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:

  1. Aglobal variable
  2. Blocal variable
  3. Cconstant
  4. 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?

  1. AVariables no longer need names
  2. BEach one can be written and tested on its own
  3. CThe program always runs faster
  4. 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?

  1. AStoring a pupil’s date of birth
  2. BRolling a dice in a board game
  3. CSorting a list of names
  4. 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?

  1. AChecking that data entered is sensible before it is used
  2. BConfirming who the user is
  3. CMaking sure the data is definitely correct
  4. 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:

  1. Aformat check
  2. Brange check
  3. Cpresence check
  4. 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?

  1. ATesting code with sample data
  2. BConfirming the identity of a user
  3. CTranslating code into machine code
  4. 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?

  1. AWriting everything without indentation
  2. BUsing meaningful variable names
  3. CRemoving all comments
  4. 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?

  1. ATo make the code shorter
  2. BTo translate the code into machine code
  3. CTo prove that the code will never, ever contain a single error
  4. 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?

  1. A-3
  2. B12
  3. C21
  4. 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?

  1. ASo the test does not need to be run
  2. BSo the data passes validation
  3. CSo the actual result can be compared with it
  4. 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?

  1. AA rounding error
  2. BA runtime error
  3. CA syntax error
  4. 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?

  1. AA rounding error
  2. BA runtime error
  3. CA syntax error
  4. 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?

  1. AThe code still runs, so no error message appears
  2. BThe translator deliberately hides them from the programmer
  3. CThey only happen on some computers
  4. 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

02 / Exam questionsMarked by levels

Exam questions on this topic

Write your answer first, on paper. Then open it and tick off the points you made. The marks are as on that board’s paper.

6 marks / Making cash machine software robustEdexcel

A bank’s developers are writing new software for its cash machines. The software reads the customer’s card and PIN, checks the balance with the bank’s server and pays out notes.

Discuss how the developers could make sure the software is robust.

What a full answer includes
  • Input validation, such as checking the PIN is exactly four digits and the amount is a multiple of the notes held, stops bad data causing errors.
  • The software should handle problems such as a lost connection to the server without crashing or paying out wrongly.
  • Testing with normal, boundary and erroneous data, such as the maximum withdrawal and letters for an amount, shows the software copes with every kind of input.
  • Code reviews, where other developers read the code, find mistakes and weaknesses that testing may miss.
  • An audit trail logs every action, such as each withdrawal and failed PIN, so problems and fraud can be traced.
  • A justified conclusion, for example that several methods are needed because a fault could cost customers or the bank money.

Model answer

Robust software keeps working correctly even when it receives unexpected input or something goes wrong. For a cash machine this matters because a fault could pay out the wrong amount or lock customers out. First, the developers should validate every input. The PIN should be checked to be exactly four digits, and the amount should be checked to be a multiple of the notes in the machine and below the daily limit. They should also plan for problems, such as the connection to the bank’s server dropping halfway through, so the software cancels the transaction safely instead of crashing or paying out without updating the balance. Second, the software must be tested thoroughly with normal data (a £20 withdrawal), boundary data (exactly the daily limit) and erroneous data (letters typed as an amount). Code reviews, where other developers read through the code, would find mistakes and security weaknesses that tests miss. Finally, an audit trail should record every withdrawal, failed PIN attempt and error. If something goes wrong, the bank can trace what happened and spot fraud. No single method is enough, so the developers should combine validation, testing, code reviews and an audit trail.

Where marks slip

Answers often name methods such as “testing” without saying what would be tested here. Give examples from the cash machine for each method, like the exact data you would test with.

03 / In the appShow Working

All 61 questions in Show Working

This page shows 40 of them. In the app, choose your exam board and you only see what your exam asks for. Tap through questions, or open Read the answers to see the whole topic at once, covered until you tap.

More GCSE Computer Science topics

Our own questions, written for every board. Show Working is independent and not affiliated with any exam board.

Show WorkingFree on the App StoreFree in your browser, no download

Open it free