0% found this document useful (0 votes)
2 views

Additional Programming Revision (1)

The document contains a series of programming exercises and tasks related to Python, including calculating areas and volumes, validating grid references, and solving a sliding puzzle. It includes code snippets, trace tables, and requirements for writing algorithms or completing existing code. The exercises are designed for students to demonstrate their understanding of programming concepts and Python syntax.

Uploaded by

REaan GAmez
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)
2 views

Additional Programming Revision (1)

The document contains a series of programming exercises and tasks related to Python, including calculating areas and volumes, validating grid references, and solving a sliding puzzle. It includes code snippets, trace tables, and requirements for writing algorithms or completing existing code. The exercises are designed for students to demonstrate their understanding of programming concepts and Python syntax.

Uploaded by

REaan GAmez
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/ 43

Name: ________________________

Programming Revision Class: ________________________

Date: ________________________

Time: 88 minutes

Marks: 71 marks

Comments:

GEMS FOUNDERS SCHOOL- AL BARSHA Page 1 of 43


The figure below shows a program written in Python that calculates the area of a rectangle or the
1. volume of a box from the user inputs.

def calculate(width, length, height):


if height == -1:
return width * length
else:
return width * length * height

numOne = int(input("Enter width: "))


numTwo = int(input("Enter length: "))
numThree = int(input("Enter height, –1 to ignore: "))

answer = calculate(numOne, numTwo, numThree)

if numThree == -1:
print(f"Area {answer}")
else:
print(f"Volume {answer}")

(a) Complete the trace table using the program in the figure above.

numOne numTwo numThree Final output

5 6 –1

10 4 0

3 5 10

(3)

(b) Describe one way that the program in the figure above could be made more robust.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(1)
(Total 4 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 2 of 43


A programmer is writing a game. The game uses a 3 x 3 grid containing nine squares.
2.
Figure 1

In the game, a square on the grid is referred to by a letter and a number.


For example, square C3 in Figure 1 contains an X.

Figure 2 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 2

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

GEMS FOUNDERS SCHOOL- AL BARSHA Page 3 of 43


Extend the program from Figure 2 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.

The answer grid contains vertical lines to help you indent your code.
(Total 6 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 4 of 43


check = False
while check == False:

square = ""

while len(square) != 2:

square = input("Enter grid reference (eg C2): ")

square = square.upper()

GEMS FOUNDERS SCHOOL- AL BARSHA Page 5 of 43


Develop an algorithm, using either pseudo-code or a flowchart, that:
3.
• initialises a variable called regValid to False
• sets a variable called regValid to True if the string contained in the variable reg is an
uppercase R followed by the character representation of a single numeric digit.

Examples:
• if the value of reg is R0 or R9 then regValid should be True
• if the value of reg is r6 or Rh then regValid should be False

You may wish to use the subroutine isDigit(ch) in your answer. The subroutine isDigit
returns True if the character parameter ch is a string representation of a digit and False
otherwise.

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________

_______________________________________________________________________
(Total 3 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 6 of 43


A program is being written to solve a sliding puzzle.
4.
• The sliding puzzle uses a 3 x 3 board.
• The board contains eight tiles and one blank space.
• Each tile is numbered from 1 to 8
• On each turn, a tile can only move one position up, down, left, or right.
• A tile can only be moved into the blank space if it is next to the blank space.
• The puzzle is solved when the tiles are in the correct final positions.

Figure 1 shows an example of how the tiles might be arranged on the board at the start of the
game with the blank space in the position (0, 1).

Figure 2 shows the correct final positions for the tiles when the puzzle is solved.

The blank space (shown in black) is represented in the program as number 0

Figure 1 Figure 2

GEMS FOUNDERS SCHOOL- AL BARSHA Page 7 of 43


The table below describes the purpose of three subroutines the program uses.

Subroutine Purpose

Returns the number of the tile on the board


in the position (row, column)

getTile(row, column) For example:


• getTile(1, 0) will return the value 5 if
it is used on the board in Figure 3
• getTile(1, 2) will return the value 0 if
it is used on the board in Figure 3.
Moves the tile in position (row, column) to
the blank space, if the blank space is next to
that tile.

If the position (row, column) is not next to


the blank space, no move will be made.
move(row, column)
For example:
• move(0, 2) would change the board
shown in Figure 3 to the board shown in
Figure 4
• move(2, 0) would not make a move if
used on the board shown in Figure 3.
Displays the board showing the current
displayBoard()
position of each tile.

Figure 3 Figure 4

GEMS FOUNDERS SCHOOL- AL BARSHA Page 8 of 43


The Python program shown in Figure 5 uses the subroutines in the table above.

The program is used with the board shown in Figure 6.

Figure 5

if getTile(1, 0) == 0:
move(2, 0)
if getTile(2, 0) == 0:
move(2, 1)
displayBoard()

Figure 6

Complete the board to show the new positions of the tiles after the program in Figure 5 is run.

(Total 2 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 9 of 43


A program is being written to solve a sliding puzzle.
5.
• The sliding puzzle uses a 3 x 3 board.
• The board contains eight tiles and one blank space.
• Each tile is numbered from 1 to 8
• On each turn, a tile can only move one position up, down, left, or right.
• A tile can only be moved into the blank space if it is next to the blank space.
• The puzzle is solved when the tiles are in the correct final positions.

Figure 1 shows an example of how the tiles might be arranged on the board at the start of the
game with the blank space in the position (0, 1).

Figure 2 shows the correct final positions for the tiles when the puzzle is solved.

The blank space (shown in black) is represented in the program as number 0

Figure 1 Figure 2

GEMS FOUNDERS SCHOOL- AL BARSHA Page 10 of 43


Table 1 describes the purpose of three subroutines the program uses.

Table 1

Subroutine Purpose

Returns the number of the tile on the board


in the position (row, column)

getTile(row, column) For example:


• getTile(1, 0) will return the value 5 if
it is used on the board in Figure 3
• getTile(1, 2) will return the value 0 if
it is used on the board in Figure 3.
Moves the tile in position (row, column) to
the blank space, if the blank space is next to
that tile.

If the position (row, column) is not next to


the blank space, no move will be made.
move(row, column)
For example:
• move(0, 2) would change the board
shown in Figure 3 to the board shown in
Figure 4
• move(2, 0) would not make a move if
used on the board shown in Figure 3.
Displays the board showing the current
displayBoard()
position of each tile.

Figure 3 Figure 4

GEMS FOUNDERS SCHOOL- AL BARSHA Page 11 of 43


Table 2 shows a description of the getTile subroutine previously described in more detail in
Table 1.

Table 2

Subroutine Purpose

Returns the number of the tile on the board in the


getTile(row, column)
position (row, column)

Figure 5 and Figure 6 show example boards.

Figure 5 Figure 6

Write a Python program to:


• check that in the first row:
◦ the second tile number is one more than the first tile number
◦ the third tile number is one more than the second tile number
• display Yes when the row meets both conditions above
• display No when the row does not meet both conditions above.

For example:
• for the board in Figure 5, the program would display No
• for the board in Figure 6, the program would display Yes

You must use the getTile subroutine in your Python code.

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

The answer grid below contains vertical lines to help you indent your code accurately.
(Total 4 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 12 of 43


GEMS FOUNDERS SCHOOL- AL BARSHA Page 13 of 43
A program is being written to solve a sliding puzzle.
6.
• The sliding puzzle uses a 3 x 3 board.
• The board contains eight tiles and one blank space.
• Each tile is numbered from 1 to 8
• On each turn, a tile can only move one position up, down, left, or right.
• A tile can only be moved into the blank space if it is next to the blank space.
• The puzzle is solved when the tiles are in the correct final positions.

Figure 1 shows an example of how the tiles might be arranged on the board at the start of the
game with the blank space in the position (0, 1).

Figure 2 shows the correct final positions for the tiles when the puzzle is solved.

The blank space (shown in black) is represented in the program as number 0

Figure 1 Figure 2

GEMS FOUNDERS SCHOOL- AL BARSHA Page 14 of 43


Table 1 describes the purpose of three subroutines the program uses.

Table 1

Subroutine Purpose

Returns the number of the tile on the board


in the position (row, column)

getTile(row, column) For example:


• getTile(1, 0) will return the value 5 if
it is used on the board in Figure 3
• getTile(1, 2) will return the value 0 if
it is used on the board in Figure 3.
Moves the tile in position (row, column) to
the blank space, if the blank space is next to
that tile.

If the position (row, column) is not next to


the blank space, no move will be made.
move(row, column)
For example:
• move(0, 2) would change the board
shown in Figure 3 to the board shown in
Figure 4
• move(2, 0) would not make a move if
used on the board shown in Figure 3.
Displays the board showing the current
displayBoard()
position of each tile.

Figure 3 Figure 4

GEMS FOUNDERS SCHOOL- AL BARSHA Page 15 of 43


Table 2 describes the purpose of another two subroutines the program uses.

Table 2

Subroutine Purpose

Returns True if the puzzle has been solved.


solved()
Otherwise returns False

Returns True if there is a blank space next


to the tile on the board in the position (row,
checkSpace(row, column) column)
Otherwise returns False

Table 3 shows a description of the move subroutine previously described in more detail in Table
1.

Table 3

Subroutine Purpose

Moves the tile in position (row, column) to the


blank space, if the blank space is next to that tile.
move(row, column)
If the position (row, column) is not next to the
blank space, no move will be made.

Write a Python program to help the user solve the puzzle.

The program should:


• get the user to enter the row number of a tile to move
• get the user to enter the column number of a tile to move
• check if the tile in the position entered is next to the blank space
◦ if it is, move that tile to the position of the blank space
◦ if it is not, output Invalid move
• repeat these steps until the puzzle is solved.

You must use the subroutines in Table 2 and Table 3.

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

The answer grid below contains vertical lines to help you indent your code accurately.
(Total 6 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 16 of 43


GEMS FOUNDERS SCHOOL- AL BARSHA Page 17 of 43
Figure 1 shows a subroutine represented using pseudo-code.
7.
Figure 1

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.

(a) Complete the trace table for the subroutine call calculate(50)

You may not need to use all the rows in the table.

n a b OUTPUT

50

(4)

(b) State the value that will be output for the subroutine call calculate(1)

___________________________________________________________________

___________________________________________________________________
(1)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 18 of 43


(c) The identifier for the variable b in Figure 1 was not a good choice.

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

___________________________________________________________________

___________________________________________________________________
(1)

(d) A REPEAT…UNTIL iteration structure was used in Figure 1.

Figure 1 has been included again below.

Figure 1

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

Figure 2 shows another subroutine called calculate that uses a WHILE…ENDWHILE


iteration structure.

Figure 2

SUBROUTINE calculate(n)
a ← n
b ← 0
WHILE a > 1
a ← a DIV 2
b ← b + 1
ENDWHILE
OUTPUT b
ENDSUBROUTINE

One difference in the way the subroutines in Figure 1 and Figure 2 work is:
• the REPEAT…UNTIL iteration structure in Figure 1 loops until the condition is true
• the WHILE…ENDWHILE iteration structure in Figure 2 loops until the condition is false.

GEMS FOUNDERS SCHOOL- AL BARSHA Page 19 of 43


Describe two other differences in the way the subroutines in Figure 1 and Figure 2 work.

1. ________________________________________________________________

___________________________________________________________________

___________________________________________________________________

2. ________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)
(Total 8 marks)

(a) Four subroutines are shown below.


8.
SUBROUTINE main(k)
OUTPUT k
WHILE k > 1
IF isEven(k) = True THEN
k ← decrease(k)
ELSE
k ← increase(k)
ENDIF
OUTPUT k
ENDWHILE
ENDSUBROUTINE

SUBROUTINE decrease(n)
result ← n DIV 2
RETURN result
ENDSUBROUTINE

SUBROUTINE increase(n)
result ← (3 * n) + 1
RETURN result
ENDSUBROUTINE

SUBROUTINE isEven(n)
IF (n MOD 2) = 0 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDSUBROUTINE

GEMS FOUNDERS SCHOOL- AL BARSHA Page 20 of 43


Complete the table showing all of the outputs from the subroutine call main(3)

The first output has already been written in the trace table. You may not need to use all
rows of the table.

Output

(4)

(b) Describe how the developer has used the structured approach to programming.

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(2)
(Total 6 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 21 of 43


This question is about a dice game played against a computer.
9.
The aim of the game is to get as close to a score of 21 as you can, without going over 21. If your
score goes over 21 then you lose.

The player’s score starts at 0.

For each turn:

• two dice (each numbered from 1 to 6) are rolled


• the total of the two dice rolls is added to the player’s score
• the value of each dice and the player’s new total is output
• if the current score is less than 21, the player is asked if they would like to roll the dice
again: if the player says yes, they get another turn; otherwise, the game ends.

At the end of the game, the program should work as follows:

• if the final score is 21, output a message to say the player has won
• if the final score is greater than 21, output a message to say the player has lost
• if the final score is less than 21, the program generates a random number between 15 and
21 inclusive:
○ if this random number is greater than the player’s final score, output a message to
say the player has lost
○ otherwise, output a message to say the player has won.

The figure below shows the output of a program that plays this dice game.

Roll 1: 1
Roll 2: 4
Current score: 5
Would you like to roll again? yes

Roll 1: 1
Roll 2: 6
Current score: 12
Would you like to roll again? yes

Roll 1: 1
Roll 2: 2
Current score: 15
Would you like to roll again? yes

Roll 1: 6
Roll 2: 1
Current score: 22
You lost!

GEMS FOUNDERS SCHOOL- AL BARSHA Page 22 of 43


Write a Python program to simulate this game.

The first line has been written for you in the answer grid.

The dice rolls are carried out by the program generating random numbers between 1 and 6. You
will need to use the Python function random.randrange(a, b) which generates a random
integer in the range a to b starting at a but finishing one before b.

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

The answer grid below contains vertical lines to help you indent your code.
(Total 11 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 23 of 43


import random

GEMS FOUNDERS SCHOOL- AL BARSHA Page 24 of 43


The figure below shows an algorithm, represented using pseudo-code.
10.
days ← [10, 15, 4]
sales ← [20, 33, 12]
weeks ← [0, 0, 0]
FOR i ← 0 TO 2
daysTotal ← days[i] + sales[i]
weeks[i] ← daysTotal DIV 7
ENDFOR
weeksTotal ← weeks[0] + weeks[1] + weeks[2]
OUTPUT weeksTotal

The DIV operator is used for integer division.

Complete the trace table for the algorithm in the figure above.

Part of the table has already been filled in.

You may not need to use all the rows in the table.

weeks
i daysTotal weeksTotal
[0] [1] [2]

0 0 0

(Total 6 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 25 of 43


(a) Which of the following best describes a data structure?
11.
Shade one lozenge.

A A number with a fractional part

B A value such as a whole number

C All of the data used and stored within a program

D An organised collection of values

(1)

(b) The figure below shows an incomplete algorithm, represented using pseudo-code.

The algorithm is used to store and manage books using records.

The algorithm should do the following:


• create a record definition called Book with the fields bookName, author and price
• create a variable for each book using the record definition.

Complete the figure below by filling in the gaps using the items in the table below.

• You may need to use some of the items in the table more than once.
• You will not need to use all the items in the table.

1 2 author

B1 B2 Book

bookName i Real

OUTPUT String Boolean

RECORD _____________

bookName : String

_____________ : String

price : ______________

ENDRECORD

B1 ← Book("The Book Thief", "M Zusak", 9.99)

B2 ← _____________ ("Divergent", "V Roth", 6.55)


(3)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 26 of 43


(c) Write an algorithm using pseudo-code to display the name of the most expensive book.

The algorithm should:


• compare the price of B1 and the price of B2
• output the book name of the most expensive book
• output Neither if the books are the same price.

The algorithm should work for any values stored in B1 and B2

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________

___________________________________________________________________
(3)
(Total 7 marks)

The figure below shows a binary search algorithm that has been programmed in Python.
12.
animals = ["cat", "dog", "hippo", "llama", "ox",
"rat", "tiger", "wolf"]
animalToFind = input("What animal would you like to
find? ")
validAnimal = False
start = 0
finish = len(animals) - 1
while validAnimal == False and start <= finish:
mid = (start + finish) // 2
if animals[mid] == animalToFind:
validAnimal = True
elif animalToFind > animals[mid]:
start = mid + 1
else:
finish = mid - 1
print(validAnimal)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 27 of 43


Complete the trace table for the program in the figure above if the user input is wolf

Part of the table has already been filled in.

You may not need to use all the rows in the table.

animalToFind validAnimal start finish mid

wolf False 0 7 3

(Total 4 marks)

The algorithm in the code below is a new search algorithm.


13.
arr ← [3, 4, 6, 7, 11, 14, 17, 18, 34, 42]
value ← 21
found ← False
finished ← False
i ← 0
down ← False
WHILE (found = False) AND (finished = False)
IF arr[i] = value THEN
found ← True
ELSE
IF arr[i] > value THEN
down ← True
i ← i – 1
ELSE
IF (arr[i] < value) AND (down = True) THEN
finished ← True
ELSE
i ← i + 4
ENDIF
ENDIF
ENDIF
ENDWHILE

GEMS FOUNDERS SCHOOL- AL BARSHA Page 28 of 43


Complete the trace table for the algorithm in the code above. The first row has been completed
for you. You may not need to use all rows of the trace table.

found finished i down

False False 0 False

(Total 4 marks)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 29 of 43


Mark schemes
(a) 3 marks for AO2 (apply)
1.
Maximum 2 marks if Output shows numbers or text only with no
other errors OR fully correct but contains additional characters.

Maximum 1 mark if Output shows numbers or text only or is


inconsistent AND there is at least one error, even if additional
characters present.

I. quotation marks in the Output column


3

(b) Mark is for AO2 (apply)

Maximum of 1 mark from:

• Add validation; A. by example e.g. check width/length are positive numbers //


check height is –1 or a positive number;

• Change data types used in the question to float / single / double / decimal / real
for inputs;
1
[4]

2 marks for AO3 (design), 4 marks for AO3 (program)


2.
Program Design
Note that AO3 (design) marks are for selecting appropriate techniques to
use to solve the problem, so should be credited whether the syntax of
programming language statements is correct or not and regardless of
whether the solution works.

Mark A for using the variable check within their own code;
Mark B for using selection or equivalent to check the grid references;

GEMS FOUNDERS SCHOOL- AL BARSHA Page 30 of 43


Program Logic

Mark C for correctly using an appropriate technique


(slicing/indexing/substring function) with correct syntax to extract the left
and right characters of input // for correctly comparing all nine possible
valid grid references;
Mark D for using one appropriate correct Boolean condition,
e.g. =”A” // =”2” or equivalent;
Mark E for having all the appropriate correct Boolean conditions to check
the letters and numbers AND for check being set appropriately in all
cases;
Mark F for outputting an appropriate message in a logically appropriate
location if their checks have failed;

Maximum 5 marks if any errors in code.

I. Case
I. Gaps/spaces throughout the code, except where to do so would
explicitly alter the logic of the code in a way that makes it incorrect.

Python Example 1 (fully correct)


All design marks are achieved (Marks A and B)

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

letter = square[0] (Part of C,


number = square[1] Part of C)

if letter in "ABC" and number in "123": (D)(E)


check = True
else:
print("Not valid, try again. ") (F)

A. use of single quotes for Mark E


[6]

3 marks for AO3 (program)


3.
Mark A for setting the variable regValid to True/False within a selection structure;
Mark B for using a Boolean condition that checks if the first character is an 'R';
Mark C for using a Boolean condition that checks if the second character is a digit;

Max 2 marks if any errors in the answer.

A. minor changes to variable identifiers if the meaning is still clear.

GEMS FOUNDERS SCHOOL- AL BARSHA Page 31 of 43


Example of fully correct answer:
regValid ← False [part A]
IF reg[0] = 'R' and isDigit(reg[1]) THEN [B,C]
regValid ← True [part A]
ENDIF

Example of another fully correct answer:


IF reg[0] = 'R' THEN [B]
IF isDigit(reg[1]) THEN [C]
regValid ← True [part A]
ELSE
regValid ← False [part A]
ENDIF
ELSE
regValid ← False [part A]
ENDIF

Example of 2 mark answer:


IF reg[0] = 'R' or isDigit(reg[1]) THEN [B,C]
regValid ← True [part A]
ELSE
regValid ← True [part A]
ENDIF

(only 2 marks awarded as the answer contains an error in the Boolean condition)

Example of another 2 mark answer:


IF reg[0] = 'R' or isDigit(reg[1]) THEN [B,C]
regValid ← True [part A]
ENDIF

(only 2 marks awarded as only part of mark A is given)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 32 of 43


Example of a fully correct flowchart solution:

[3]

GEMS FOUNDERS SCHOOL- AL BARSHA Page 33 of 43


2 marks for AO2 (apply)
4.

1 mark for 4 in the correct position;


1 mark for 2 in the correct position;

Maximum 1 mark if any errors.

A. 0 instead of blank space or any other sensible indicator for the blank space.
A. unaffected cell contents not shown as long as it is clear which is the blank space.
A. answers written on the diagram below if board is left blank.
[2]

1 mark for AO3 (design), 3 marks for AO3 (program)


5.
Program Design
Note that AO3 (design) marks are for selecting appropriate techniques to use to solve the
problem, so should be credited whether the syntax of programming language statements is
correct or not and regardless of whether the solution works.

Mark A for the use of a selection structure with multiple conditions // use of multiple
selection structures // an iteration structure containing one selection structure;

Program Logic
Mark B for correctly checking three consecutive values in getTile
(even if the wrong row/column);

Mark C for fully correct indices used in getTile for the first row;

Mark D for a structure that would output either Yes or No correctly in all circumstances, but
never both; A. if conditions are not fully correct

I. Case
I. Messages or no messages with input statements
I. Gaps/spaces throughout the code, except where to do so would explicitly alter the logic
of the code in a way that makes it incorrect

Maximum 3 marks if any errors in code.

GEMS FOUNDERS SCHOOL- AL BARSHA Page 34 of 43


Python Example 1 (fully correct)
Design mark is achieved (Mark A)

if getTile(0, 0) + 1 == getTile(0, 1): (Part B, Part C)


if getTile(0, 1) + 1 == getTile(0, 2): (Part B, Part C)
print("Yes") (Part D)
else:
print("No") (Part D)
else:
print("No") (Part D)

Note to examiners: in a nested if statement, all pathways must be present to award Mark
D (including the part shaded yellow above).

Python Example 2 (fully correct)


Design mark is achieved (Mark A)

if getTile(0, 0) + 1 == getTile(0, 1): (Part B, Part C)


if getTile(0, 0) + 2 == getTile(0, 2): (Part B, Part C)
print("Yes") (Part D)
else:
print("No") (Part D)
else:
print("No") (Part D)

Note to examiners: in a nested if statement, all pathways must be present to award Mark
D (including the part shaded yellow above).

Python Example 3 (fully correct)


Design mark is achieved (Mark A)

if getTile(0, 1) - getTile(0, 0) == 1 and (Part B, Part C)


getTile(0, 2) - getTile(0, 1) == 1:
print("Yes") (Part D)
else:
print("No") (Part D)
[4]

GEMS FOUNDERS SCHOOL- AL BARSHA Page 35 of 43


2 marks for AO3 (design), 4 marks for AO3 (program)
6.
Program Design
Note that AO3 (design) marks are for selecting appropriate techniques to use to solve the
problem, so should be credited whether the syntax of programming language statements is
correct or not and regardless of whether the solution works.

Mark A for the use of an indefinite iteration structure that exists within their language;

Mark B for the use of a selection structure or equivalent to check for a blank space;

Program Logic
Mark C for using user input and storing the result in two variables correctly for the row and
column;

Mark D for code that uses both the solved subroutine and the checkSpace subroutine in
logically correct locations;

Mark E for calling the move subroutine in a pathway following an = True condition (or
equivalent) with the row and column from the user input as parameters;

Mark F for outputting Invalid move when the tile does not get moved and asking the user
to input row and column again in logically correct locations; R. if user is asked to re-input
after the problem is solved.

I. Case
I. Messages or no messages with input statements
I. Gaps/spaces throughout the code, except where to do so would explicitly alter the logic
of the code in a way that makes it incorrect

Maximum 5 marks if any errors in code.

Python Example 1 (fully correct)


All design marks are achieved (Marks A and B)

while not solved(): (Part D)


row = int(input()) (Part C)
col = int(input()) (Part C)
if checkSpace(row, col): (Part D)
move(row, col) (E)
else:
print("Invalid move") (F)

GEMS FOUNDERS SCHOOL- AL BARSHA Page 36 of 43


Python Example 2 (fully correct)
All design marks are achieved (Marks A and B)

while solved() == False: (Part D)


row = int(input()) (Part C)
col = int(input()) (Part C)
if checkSpace(row, col) == True: (Part D)
move(row, col) (E)
else:
print("Invalid move") (F)
[6]

(a) 4 marks for AO2 (apply)


7.
• 1 mark for the first value of column a and the first value of column b both
correct;
• 1 mark for column a correctly integer dividing the first value in column a
by 2 down to 1 and no other values;
• 1 mark for minimum of six values in the b column, incrementing by one.
• The number of values in the b column must match the number of values
in the a column;
• 1 mark for OUTPUT being the final value of b and no other values in the
output column, and no other values in column n; A. follow through from
column b

I. Different rows used as long as the order within columns is clear


I. Duplicate values on consecutive rows within a column
4

(b) Mark is for AO2 (apply)

1;

Reject the word one


1

(c) Mark is for AO2 (apply)

1 mark for giving a new identifier that describes this purpose, eg count //
total // times // numberOfTimes // counter
1

GEMS FOUNDERS SCHOOL- AL BARSHA Page 37 of 43


(d) 2 marks for AO2 (apply)

Maximum of 2 marks from:

• The REPEAT…UNTIL structure tests the condition at the end //


• the WHILE…ENDWHILE structure tests the condition at the beginning;

• The REPEAT…UNTIL structure will always execute at least once //


• the WHILE…ENDWHILE loop may never execute;

• If the value of n is 1 (or less) then the REPEAT…UNTIL structure will cause
the value of a/b to change, but the WHILE…ENDWHILE structure will not;

R. The REPEAT…UNTIL structure repeats lines of code until a condition is true


R. The WHILE…ENDWHILE structure repeats lines of code until a condition is false
2
[8]

(a) 4 marks for AO2 (apply)


8.
first (calculated) value of 10;
next calculated value of 5;
next calculated value of 16;
all values of 8, 4, 2 and 1 in that order;

Stop marking at the first incorrect value.


Max of 3 marks if additional outputs are given.

(b) 2 marks for AO1 (understanding)

Max 2 from:

(The developer has) modularised their code // used subroutines;


(The developer has) decomposed the problem // broken the problem down into
sub-problems;
(The developer has) created interfaces (to the subroutines);
(The developer has) used parameters;
(The developer has) used return values;
(The developer has) used local variables;
2
[6]

GEMS FOUNDERS SCHOOL- AL BARSHA Page 38 of 43


4 marks for AO3 (design), 7 marks for AO3 (program)
9. Any solution that does not map to the mark scheme refer to lead
examiner

Note to Examiners: For marks E and J be careful not to penalise the


same error twice. For example, if they have used 6 instead of 7 in mark E
and then 21 instead of 22 in mark J apply a DPT

Program Design
Note that AO3 (design) marks are for selecting appropriate techniques to
use to solve the problem, so should be credited whether the syntax of
programming language statements is correct or not and regardless of
whether the solution works.

Mark A for attempting to randomly generate two numbers;


Mark B for use of selection to check the current score against 21;
Mark C for using iteration to keep rolling the dice;
Mark D for outputting the dice rolls in appropriate places;

Program Logic

Mark E for generating two random numbers between 1 and 6 inclusive;


Mark F for correctly adding the two dice values cumulatively to the
previous score;
Mark G for a loop that terminates if the current score is less than 21 and
player chooses not to roll again;
Mark H for a correct mechanism to end the game if the player has a
score greater than or equal to 21;
Mark I for a selection statement which correctly checks if the player has
lost (final score is greater than 21) OR won (final score is 21);
Mark J for generating a random number between 15 and 21 inclusive in a
logically correct place AND checking if the result is greater than the final
score;
Mark K for at least one correct set of messages output in appropriate
places to show whether the user has won or lost;

A. yes/y, no/n or any other appropriate equivalents

Maximum 10 marks if any errors in code.

I. Case
I. Gaps/spaces throughout the code, except where to do so would
explicitly alter the logic of the code in a way that makes it incorrect.
I. Messages or no messages with input statements

GEMS FOUNDERS SCHOOL- AL BARSHA Page 39 of 43


Python Example 1 (fully correct)
All design marks are achieved (Marks A, B, C and D)

import random
score = 0
rollAgain = "yes"

(C, Part of G,
while rollAgain == "yes":
Part of H)
dice1 = random.randrange(1, 7) (Part of A,E)
dice2 = random.randrange(1, 7) (Part of A,E)
score = score + dice1 + dice2 (F)
print(f"Roll 1: {dice1}") (D)
print(f"Roll 2: {dice2}")
print(f"Current score: {score}")
if score < 21: (Part of G)
rollAgain = input() (Part of G)
else:
rollAgain = "no"
if score > 21: (Part of H)
print("You lost! ") (Part of I)
elif score == 21: (Part of K)
print("You won! ") (Part of I)
else: (Part of K)
if random.randrange(15,22) > score: (Part of I)
print("You lost!") (J)
else: (Part of K)
print("You won! ") (Part of K)

A. random.randint(1, 6)
A. random.randint(15, 21)
[11]

GEMS FOUNDERS SCHOOL- AL BARSHA Page 40 of 43


6 marks for AO2 (apply)
10.
1 mark for the i column correct;

1 mark for the first value in the daysTotal column correct;


I. preceding zeroes

1 mark for the rest of daysTotal column correct;

1 mark for the second value of weeks[0] column correct;

1 mark for the rest of weeks columns correct;

1 mark for the correct total of weeks[0], weeks[1] and weeks[2] in the final column and
no other value;
I. preceding zeroes
A. follow through value as long as the total is correct for the three final values the student
has written in the weeks columns.

Maximum of 5 marks if any errors.

I. Different rows used so long as the order within columns is clear


I. Duplicate values on consecutive rows within a column
[6]

(a) Mark is for AO1 (understanding)


11.
D An organised collection of values;

R. If more than one lozenge shaded


1

GEMS FOUNDERS SCHOOL- AL BARSHA Page 41 of 43


(b) 3 marks for AO2 (apply)

3 marks if all four are correct:


• Book on line 1
• author on line 3
• Real on line 4
• Book on line 7

2 marks if any three are correct


1 mark if any two are correct

1 RECORD Book

2 bookName : String

3 author : String

4 price : Real

5 ENDRECORD

6 B1 Book("The Book Thief", "M Zusak", 9.99)

7 B2 Book("Divergent", "V Roth", 6.55)

I. Case
3

(c) 3 marks for AO2 (apply)


IF B1.price > B2.price THEN
OUTPUT B1.bookName
ELSEIF B1.price < B2.price THEN
OUTPUT B2.bookName
ELSE
OUTPUT "Neither"
ENDIF

1 mark for correctly using a selection structure with multiple conditions // use of
multiple selection structures to compare B1 and B2 in some way (even if Boolean
conditions incorrect);

1 mark for correct Boolean conditions throughout to compare the prices;

1 mark for displaying the correct output in each case;

Max 2 marks if any errors

I. Case
A. Pseudo-code statements written using different syntax as long as the logic is still
correct.
3
[7]

GEMS FOUNDERS SCHOOL- AL BARSHA Page 42 of 43


4 marks for AO2 (apply)
12.

1 mark for correct animalToFind, validAnimal and finish columns


and no other values;
1 mark for correct start column and no other values;
1 mark for having 5 as second value in mid column;
1 mark for the rest of mid column being correct and no other values;

Maximum 3 marks if any errors.

I. different rows used as long as the order within columns is clear


I. duplicate values on consecutive rows within a column
[4]

4 marks for AO2


13.
1 mark for values 4 and 8 in the i column (in that order);
1 mark for value 7 as the last value in the i column;
1 mark for down being set only once to True;
1 mark for finished being set only once to True;

Max 3 marks if any errors.

I. repeated values written in columns


I. exact placing of values as long as the vertical order is correct

Correct table as follows:

[4]

GEMS FOUNDERS SCHOOL- AL BARSHA Page 43 of 43

You might also like