Programming Concepts (AQA GCSE Computer Science)

Exam Questions

2 hours32 questions
11 mark

The pseudocode in Figure 1 assigns two string values to two variables.

Figure 1

title ← 'computer science'
level ← 'gcse'

Identify one choice that shows the length of the contents of the variable level in Figure 1.

  • 1

  • 2

  • 3

  • 4

Did this page help you?

2a1 mark

The algorithm in Figure 2 has been developed to automate the quantity of dog box biscuits to put in a dog bowl at certain times of the day.

Line numbers are included but are not part of the algorithm.

Figure 2

1 time ← USERINPUT
2 IF time = 'breakfast' THEN
3    q ← 1
4 ELSE IF time = 'lunch' THEN
5    q ← 4
6 ELSE IF time = 'dinner' THEN
7    q ← 2
8 ELSE
9    OUTPUT 'time not recognised'
10 ENDIF
11 FOR n ← 1 TO q
12   IF n < 3 THEN
13      DISPENSE_BISCUIT('chewies')
14   ELSE
15      DISPENSE_BISCUIT('crunchy')
16   ENDIF
17 ENDFOR

Identify one choice which shows the line number where selection is first used in the algorithm shown in Figure 2.

  • Line number 2

  • Line number 4

  • Line number 9

  • Line number 12

2b1 mark

Identify one choice which shows the line number where iteration is first used in the algorithm shown in Figure 2.

  • Line number 1

  • Line number 8

  • Line number 11

  • Line number 13

Did this page help you?

31 mark

The algorithm in Figure 4 is a sorting algorithm

  • Array indexing starts at 0.

  • Line numbers are included but are not part of the algorithm.

Figure 4

1 arr ← [4, 1, 6]
2 swapsMade ← false
3 WHILE swapsMade = false
4    swapsMade ← true
5    i  ←  0
6    WHILE i < 2
7       IF arr[i+1] < arr[i] THEN
8          t ← arr[i]
9          arr[i] ← arr[i+1]
10         arr[i+1] ← t
11         swapsMade ← false
12      ENDIF
13      i ← i + 1
14   ENDWHILE
15 ENDWHILE

Identify one choice to show which of the following contains the false statement about the algorithm in Figure 4.

  • The algorithm uses a named constant

  • The algorithm uses indefinite iteration

  • The algorithm uses nested iteration

Did this page help you?

41 mark

Figure 8.

1 num1 = int(input())
2 num2 = int(input())
3 hcf = 1
4 count = 1
5 while count < num1:
6    if (num1 % count == 0 and num2 % count == 0):
7      hcf = count
8    count = count + 1
9 print(hcf)

State the output from the program in Figure 8 when the user enters the numbers 4 and 4.

Did this page help you?

51 mark

Figure 1 shows an algorithm, represented using pseudocode, which assigns a different value to four variables.

Figure 1

country ← 'United States of America'
state ← 'California'
city ← 'San Francisco'
landmark ← 'Alcatraz Island'

The subroutine POSITION finds the first position of a character in a string.

For example, POSITION('Computing', 'p') would return 3.

The variable z is assigned a value using the statement:

z ← POSITION(landmark, 't')

What value is assigned to z?

Identify one choice.

  • -1

  • 3

  • 4

  • 5

Did this page help you?

61 mark

Figure 2

1 again ←True
2 WHILE again = True
3    a ← USERINPUT
4    IF a > 0 THEN
5       counter ← 0
6       WHILE a > 0
7         a ← a DIV 3
8         counter ← counter + 1
9       ENDWHILE
10   ELSE
11      again ← False
12   ENDIF
13   OUTPUT a
14 ENDWHILE

Where is iteration first used in the algorithm in Figure 2?

Identify one choice.

Did this page help you?

71 mark

Figure 8 box shows an algorithm, written using pseudocode, that uses a RECORD data structure for storing information about a film.

Each record stores four pieces of information about a film:

  • film title

  • certificate (eg 12A, PG)

  • year the film was made

  • if the film is currently being shown at a cinema.

There are records for three films and these films are stored alphabetically in an array called filmCollection.

The pseudocode outputs the title of the newest of the three films.

  • Part of the algorithm has been replaced by the label L1.

RECORD Film
  title : String
  certificate : String
  year : Integer
  beingShown : Boolean
ENDRECORD
hulk ← Film('Hulk', '12A', 2005, False)
ironMan ← Film('Iron Man', '12A', 2008, False)
antMan ← Film('Ant-Man', '12A', 2015, False)
filmCollection ← [antMan, hulk, ironMan]
year ← 0
position ← 0

FOR i ← 0 TO L1
  IF filmCollection[i].year > year THEN
    year ← filmCollection[i].year
    position ← i
  ENDIF
ENDFOR

OUTPUT filmCollection[position].title, ' is the
newest film'

Which assignment statement changes the year the film Hulk was made to 2003?

Identify one choice.

  • hulk.year ← 2003

  • filmCollection[0].year ← 2003

  • Film(year) ← 2003

  • hulk(year) ← 2003

Did this page help you?

8a1 mark

Identify one choice that shows the line number where selection is first used in the algorithm in Figure 1.

Figure 1

1 i ← USERINPUT
2 IF i MOD 2 = 0 THEN
3    OUTPUT i * i
4 ELSE
5    OUTPUT i
6 ENDIF
  • Line number 1

  • Line number 2

  • Line number 3

  • Line number 4

8b1 mark

Identify one choice that shows the output from the algorithm in Figure 1 when the user input is 4

  • 0

  • 2

  • 4

  • 8

  • 16

8c1 mark

Identify one choice that shows the line number where assignment is first used in the algorithm in Figure 1.

  • Line number 1

  • Line number 2

  • Line number 3

  • Line number 4

8d1 mark

Figure 2 shows an implementation of the algorithm in Figure 1 using the Python programming language.

  • Line numbers are included but are not part of the program.

Figure 2

1 i = int(input("Enter a number: "))
2 if i % 2 == 0:
3    print(i * i)
4 else:
5    print(i)

The program in Figure 2 needs to be changed so that it repeats five times using definite (count controlled) iteration.

Identify one choice next to the program that does this correctly.

  • for x in range(0, 5):
      i = int(input("Enter a number: "))
      if i % 2 == 0:
         print(i * i)
      else:
         print(i)
  • for x in range(0, 6):
      i = int(input("Enter a number: "))
      if i % 2 == 0:
         print(i * i)
      else:
         print(i) 
  • x = 1
    while x != 6:
      i = int(input("Enter a number: "))
      if i % 2 == 0:
         print(i * i)
      else:
         print(i)
      x = x + 1 
  • x = 6
    while x != 0:
      i = int(input("Enter a number: "))
      if i % 2 == 0:
         print(i * i)
      else:
         print(i)
      x = x – 1

Did this page help you?

9a2 marks

Figure 3

orderTotal ← USERINPUT
deliveryDistance ← USERINPUT
deliveryCost ← 0.0
messageOne ← "Minimum spend not met"
messageTwo ← "Delivery not possible"
IF deliveryDistance ≤ 5 AND orderTotal > 0.0 THEN
   IF orderTotal > 50.0 THEN
      deliveryCost ← 1.5
      OUTPUT deliveryCost
   ELSE IF orderTotal > 25.0 THEN
      deliveryCost ← (orderTotal / 10) * 2
      OUTPUT deliveryCost
   ELSE
      OUTPUT messageOne
   ENDIF
ELSE
   OUTPUT messageTwo
ENDIF

Using Figure 3, complete the table.

Input value of orderTotal

Input value of deliveryDistance

Output

55.5

2

35.0

5

9b1 mark

State how many possible values the result of the comparison deliveryDistance ≤ 5 could have in the algorithm shown in Figure 3.

Did this page help you?

10a1 mark

The two Python programs in Figure 5 output the value that is equivalent to adding box together the integers between 1 and an integer entered by the user.

For example, if the user entered the integer 5, both programs would output 15

Figure 5

Program A

print("Enter a number: ")
num = int(input())
total = 0
for i in range(1, num + 1):
 total = total + i
print(total) 

Program B

print("Enter a number: ")
num1 = int(input())
num2 = num1 + 1
num2 = num1 * num2
num2 = num2 // 2
print(num2)

Identify one choice to indicate which of the statements is true about the programs in Figure 5.

  • Both programs are equally efficient.

  • Program A is more efficient than Program B.

  • Program B is more efficient than Program A

10b2 marks

Justify your answer for Question 10a

Did this page help you?

111 mark

Figure 9 shows a subroutine represented using pseudocode.

Figure 9

SUBROUTINE calculate(n)
   a ← n
   b ← 0
   REPEAT
      a ← a DIV 2
      b ← b + 1
   UNTIL a ≤ 1
   OUTPUT b
ENDSUBROUTINE

The DIV operator is used for integer division.

The identifier for the variable b in Figure 9 was not a good choice

State a better identifier for this variable that makes the algorithm easier to read and understand.

Did this page help you?

124 marks

A program is being developed in Python to simulate box a card game

Throughout the game each player always has 100 cards. Each card displays a number.

Players take it in turns to swap one of their cards with another random card from a set of cards until a player has a run of five numbers in sequence within their 100 cards.

Figure 14 shows part of the program that will get a player to enter the position of a card to swap.

Figure 14

position = int(input("Enter card position: "))

Extend the program in Figure 14. Your answer must be written in Python.

The program should keep getting the user to enter the card position until they enter a card position that is between 1 and 100 inclusive.

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?

131 mark

Figure 1

1 seconds ← 0
2 rest ← 50
3 REPEAT
4     bpm ← getBPM()
5     effort ← bpm – rest
6     IF effort ≤ 30 THEN
7        OUTPUT 'faster'
8     ELSE
9        IF effort ≤ 50 THEN
10         OUTPUT 'steady'
11       ELSE
12         OUTPUT 'slower'
13       ENDIF
14     ENDIF
15     wait(60)
16     seconds ← seconds + 60
17 UNTIL seconds > 200

State the line number where iteration is first used in the algorithm shown in Figure 1.

Did this page help you?

1a1 mark

The algorithm in Figure 2 has been developed to automate the quantity of dog box biscuits to put in a dog bowl at certain times of the day.

  • Line numbers are included but are not part of the algorithm.

Figure 2

1  time ← USERINPUT
2  IF time = 'breakfast' THEN
3    q ← 1
4  ELSE IF time = 'lunch' THEN
5    q ← 4
6  ELSE IF time = 'dinner' THEN
7    q ← 2
8  ELSE
9  OUTPUT 'time not recognised'
10 ENDIF
11 FOR n ← 1 TO q
12     IF n < 3 THEN
13        DISPENSE_BISCUIT('chewies')
14     ELSE
15        DISPENSE_BISCUIT('crunchy')
16     ENDIF
17 ENDFOR

Identify one choice which shows how many times the subroutine DISPENSE_BISCUIT would be called if the user input is 'breakfast' in Figure 2.

  • 1 subroutine call

  • 2 subroutine calls

  • 3 subroutine calls

  • 4 subroutine calls

1b1 mark

State how many times the subroutine DISPENSE_BISCUIT will be called with the parameter 'chewies' if the user input is 'lunch' in Figure 2.

Did this page help you?

25 marks

A programmer has written a Python program that asks the user to input two integers and then output which of the two integers is the largest.

Complete the program below by filling in the gaps using the items in Figure 3. You will not need to use all the items in Figure 3.

Each item in Figure 3 should only be used once.

Figure 3

print num1 num2 output

else: < > elif

str float int

num1 = int(input("Enter a number: "))

num2 = (input("Enter a second number: "))

if num1 > num2:

      print("___________ is bigger.")

elif num1 ______________num2:

      print("_____________ is bigger.")
________________

      print("The numbers are equal.")

Did this page help you?

37 marks

Write a Python program that allows a taxi company to calculate how much a box taxi fare should be.

The program should:

  • allow the user to enter the journey distance in kilometres (no validation is required)

  • allow the user to enter the number of passengers (no validation is required)

  • calculate the taxi fare by

    • charging £2 for every passenger regardless of the distance

    • charging a further £1.50 for every kilometre regardless of how many passengers there are

  • output the final taxi fare.

You should use meaningful variable name(s), correct syntax and indentation in your answer.

Did this page help you?

45 marks

Write a Python program that inputs a password and checks if it is correct.

Your program should work as follows:

  • input a password and store it in a suitable variable

  • if the password entered is equal to secret display the message Welcome

  • if the password entered is not equal to secret display the message Not welcome.

You should use meaningful variable name(s), correct syntax and indentation in your answer.

Did this page help you?

51 mark

A programmer has written the Python program in Figure 5 to add up the numbers between one and five.

Figure 5

total = 0
for number in range(1, 6):
    total = total + number
print(total)

The program needs to be changed so that it also multiplies all of the numbers between one and five.

Identify one choice next to the program that will do what the programmer wants.

  • total = 0
    product = 1
    for number in range(1, 6):
      total = total + number
      product = total * number
    print(total)
    print(product)
  • total = 0
    product = 1
    for number in range(1, 6):
      total = total + number
      product = product * number
    print(total)
    print(product)
  • total = 0
    product = 1
    for number in range(1, 6):
      total = total + number
      product = product * total
    print(total)
    print(product)
  • total = 0
    product = 1
    for number in range(1, 6):
      total = total + number
      product = (total + product) * number
    print(total)
    print(product)

Did this page help you?

61 mark

A program has been written in Python to display all the odd integers between 1 and the largest odd number smaller than an integer entered by the user. The program is shown in Figure 6.

Figure 6

odd = 1
number = int(input("Enter an integer: "))
while odd != number:
  print(odd)
  odd = odd + 2
print("Finished!")

The program works correctly if the integer entered by the user is an odd, positive integer. For example, if 7 is entered the program correctly displays the values 1, 3 and 5

The program does not work correctly if an odd integer less than 1 is entered by the user. For example, when -7 is entered the program should display the values 1, -1, -3 and -5 but it does not do this.

Using Python only, change the program code inside the while loop so that it will work correctly for any odd integer entered by the user.

Did this page help you?

7a2 marks

Figure 2 shows an algorithm that uses integer division which has been represented using pseudocode.

  • Line numbers are included but are not part of the algorithm

Figure 2

1 again ← True
2 WHILE again = True
3   a ← USERINPUT
4   IF a > 0 THEN
5     counter ← 0
6     WHILE a > 0
7       a ← a DIV 3
8       counter ← counter + 1
9     ENDWHILE
10  ELSE
11    again ← False
12  ENDIF
13  OUTPUT a
14 ENDWHILE

Integer division is the number of times one integer divides into another, with the remainder ignored.

For example:

  • 14 DIV 5 evaluates to 2

  • 25 DIV 3 evaluates to 8

In the algorithm in Figure 2, what will be output when the user input is 10?

Identify one choice

  • 0

  • 1

  • 2

  • 4

7b1 mark

In the algorithm in Figure 2, what is the largest possible value of the variable counter when the user input is 36?

Identify once choice

  • 0

  • 2

  • 4

  • 5

Did this page help you?

81 mark

Figure 8

RECORD Film
   title : String
   certificate : String
   year : Integer
   beingShown : Boolean
ENDRECORD
hulk ← Film('Hulk', '12A', 2005, False)
ironMan ← Film('Iron Man', '12A', 2008, False)
antMan ← Film('Ant-Man', '12A', 2015, False)
filmCollection ← [antMan, hulk, ironMan]
year ← 0
position ← 0

FOR i ← 0 TO ①
 IF filmCollection[i].year > year THEN
    year ← filmCollection[i].year
    position ← i
 ENDIF
ENDFOR
OUTPUT filmCollection[position].title, ' is the newest film'

What should the label ① in Figure 8 be replaced by?

Identify one choice.

  • 3

  • LEN(filmCollection)

  • C LEN(filmCollection) – 1

  • Position

Did this page help you?

93 marks

Figure 13 shows an algorithm, represented using pseudocode, that should display box currency names in reverse alphabetical order, starting with yen.

There are errors in the logic of the algorithm.

  • Line numbers are included but are not part of the algorithm.

Figure 13

1 SUBROUTINE diffCurrencies(currencies)
2      currencies ← ['baht', 'dollar', 'euro',  'koruna', 'lira', 'rand','rupee', 'yen']
3      RETURN currencies[x]
4 ENDSUBROUTINE
5
6 FOR i ← 8 TO 0 STEP 1
7     OUTPUT(diffCurrencies(i))
8 ENDFOR

Rewrite line 1 and line 6 from Figure 13 to make the algorithm work as intended.

Did this page help you?

105 marks

Write a Python program to check if an email address has been entered correctly by a box user.

Your program must:

  • get the user to input an email address

  • get the user to input the email address a second time

  • output the message Match and output the email address if the email addresses entered are the same

  • output the message Do not match if the email addresses entered are not the same.

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?

117 marks

Write a Python program box that calculates the value of a bonus payment for an employee based on how many items they have sold and the number of years they have been employed.

The program should:

  • get the user to input the number of items sold

  • get the user to input the number of years employed

  • output the value of the bonus payment:

    • if the years of employment is less than or equal to 2 and the number of items sold is greater than 100, then the bonus will be the number of items sold multiplied by 2

    • if the years of employment is greater than 2, then the bonus will be the number of items sold multiplied by 10

    • otherwise, the bonus is 0

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?

121 mark

Explain why rest could have been defined as a constant in the algorithm shown in Figure 1.

Figure 1

1 seconds ← 0
2 rest ← 50
3 REPEAT
4    bpm ← getBPM()
5    effort ← bpm – rest
6    IF effort ≤ 30 THEN
7       OUTPUT 'faster'
8    ELSE
9       IF effort ≤ 50 THEN
10         OUTPUT 'steady'
11      ELSE
12         OUTPUT 'slower'
13      ENDIF
14    ENDIF
15    wait(60)
16    seconds ← seconds + 60
17 UNTIL seconds > 200

Did this page help you?

12 marks

The algorithm in Figure 4 is a sorting algorithm

  • Array indexing starts at 0.

  • Line numbers are included but are not part of the algorithm.

Figure 4

1 arr ← [4, 1, 6]
2 swapsMade ← false
3 WHILE swapsMade = false
4     swapsMade ← true
5     i ← 0
6     WHILE i < 2
7       IF arr[i+1] < arr[i] THEN
8          t ← arr[i]
9          arr[i] ← arr[i+1]
10         arr[i+1] ← t
11         swapsMade ← false
12       ENDIF
13       i ← i + 1
14     ENDWHILE
15 ENDWHILE

The identifier swapsMade is used in the algorithm shown in Figure 4.

Explain why this is a better choice than using the identifier s.

Did this page help you?

28 marks

Write a Python program that calculates an estimate of the braking distance in box metres for a new model of go-kart that is travelling between 10 and 50 kilometres per hour (kph).

Your program should:

  • keep asking the user to enter a speed for the go-kart until they enter a speed that is between 10 and 50 (inclusive)

  • calculate the braking distance in metres by dividing the speed by 5

  • ask the user if the ground is wet (expect the user to enter yes if it is)

  • if the ground is wet, multiply the braking distance by 1.5

  • output the final calculated braking distance.

You should use meaningful variable name(s), correct syntax and indentation in your answer.

Did this page help you?

36 marks

A theme park charges £15 per person for a daily ticket. If there are six or more box people in a group, the group is given a £5 discount.

Write a Python program to calculate the total charge for a group of people visiting the theme park.

The program must:

  • Get the user to enter the number of people in a group

  • Calculate the total charge by:

    • Charging £15 per person

    • Reducing the total charge by £5 if there are six or more people

  • Output the total charge.

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?

47 marks

Figure 12 shows a line of Python code that creates a list of fruit names.

Figure 12

fruits = ["banana", "apple", "orange", "pear", "grape", "pineapple"]

Extend the program in Figure 12. Your answer must be written in Python

The program should get the user to enter a word and perform a linear search on the list fruits to find if the word is in the list or not.

The program should:

  • Ask the user what word they would like to find

  • Output the message True if the word is found

  • Output the message False if the word is not found.

You must write your own linear search routine and not use any built-in search function available in Python.

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?

56 marks

A programmer is writing a game. The game uses a 3 x 3 grid containing nine box squares.

Figure 14

Three-by-three grid with columns labelled A, B, C and rows 1, 2, 3; an 'X' is marked in the cell at column C, row 3.

In the game, a square on the grid is referred to by a letter and a number. For example, square C3 in Figure 14 contains an X.

Figure 15 shows part of a Python program that checks the grid reference entered by a player

The grid reference is valid if:

  • there are exactly two characters

  • the first character entered is A, B or C

  • the second character entered is 1, 2 or 3.

Figure 15

check = False
while check == False:
   square = ""
   while len(square) != 2:
   square = input("Enter grid reference (eg C2): ")
   square = square.upper()

The Python function upper() converts letters into uppercase, e.g. b1 would be converted to B1

Extend the program from Figure 15 so it completes the other checks needed to make sure a valid grid reference is entered.

Your extended program must:

  • use the variable check

  • repeat the following steps until a valid grid reference is entered:

    • get the user to enter a grid reference

    • output an appropriate message if the grid reference entered is not valid.

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?

66 marks

There are 500 cards within the game in total. Each card is numbered from 1 to 250 and each number appears twice in the whole set of cards.

The player’s 100 cards are always stored in numerical order

When a player has a valid run of five cards within their 100 cards they have won the game.

A valid run:

  • consists of five cards

  • can start from any position in the player’s 100 cards

  • the second card’s value is one more than the first card’s value, the third card’s value is one more than the second card’s value, the fourth card’s value is one more than the third card’s value, and the fifth card’s value is one more than the fourth card’s value.

Below are examples of valid runs which means a player has won.

Examples of card runs: Valid runs show sequential numbers like 2-6 and 99-103. Invalid runs break sequence, like skipping numbers or repeating 5.

Write a Python program to check if a player has a valid run of five cards within their 100 cards.

When writing your program you should assume:

  • there is an array called cards that contains the values of the player’s 100 cards

  • cards[0] will contain the value of the first card and cards[99] will contain the value of the last card

  • the values in cards are already stored in numerical order

  • there is a Boolean variable called gameWon that has a value of False.

Your program should set gameWon to True if there is a valid run.

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?

78 marks

Each time a player answers a question correctly the ticket array is updated; if their answer is in the ticket array then it is replaced with an asterisk (*).

An example of the ticket array containing key terms and asterisks is shown in Figure 17.

Figure 17

Grid with labelled cells; row 0: CPU, ALU, star; row 1: star, LAN; row 2: Register, Cache, star. Columns labelled 0 to 2.

Write a subroutine in Python called checkWinner that will count the number of asterisks.

The subroutine should:

  • take the ticket array as a parameter

  • count the number of asterisks in the ticket array

  • output the word Bingo if there are nine asterisks in the array

  • output the total number of asterisks if there are fewer than nine asterisks in the array.

You must write your own count routine and not use any built-in count function that might be available in Python.

You should use indentation as appropriate, meaningful variable name(s) and Python syntax in your answer.

Did this page help you?