9569/02 Computing
9569/02 Computing
in collaboration with
CAMBRIDGE ASSESSMENT INTERNATIONAL EDUCATION
General Certificate of Education Advanced Level
Higher 2
All tasks must be done in the computer laboratory. You are not allowed to bring in or take out any pieces of
work or materials on paper or electronic media or in any other form.
The use of built-in functions, where appropriate, is allowed for this paper unless stated otherwise.
Note that up to 6 marks out of 100 will be awarded for the use of common coding standards for programming
style.
The numbers of marks is given in brackets [ ] at the end of each question or part question.
The total number of marks for this paper is 100.
Instruction to candidates:
Your program code and output for each of Task 1, 2 and 3 should be downloaded in a single . ipynb
file. For example, your program code and output for Task 1 should be downloaded as
1 The IMEI number is a unique value used to identify mobile devices, such as phones and tablets.
The IMEI number has 15 digits: 14 digits with an extra check digit added to the right-hand side.
The check digit is calculated using the following algorithm, on the left-most 14 digits of an IMEI
number:
Step 1: 1 4 5 7 6 5 6 7 6 5 4 9 3 4
Step 2: 1 8 5 14 6 10 6 14 6 10 4 18 3 8
Step 3: 1 + (8) + 5 + (1 + 4) + 6 + (1 + 0) + 6 + (1 + 4) + 6 + (1 + 0) + 4 + (1 + 8) + 3 + (8)
Sum= 68
Step 4: Check digit = 2
For each of the sub-tasks, add a comment statement at the beginning of the code using the hash
symbol '#' to indicate the sub-task the program code belongs to, for example:
Ou t p u t:
Task 1.1
• validate that the parameter input_v al ue is either an integer, or a string containing a valid
integer
• check that it is 14 digits in length
• return -1 if the value received is invalid for any reason
• calculate the check digit for the given first 14 digits of the IMEI number
• return the calculated check digit. [6]
Task 1.2
Create four tests that should fully test your function. Ensure that it validates the inputs accurately
and returns the correct expected result.
Each of the four tests will be a pair of data items: the input value and its expected result.
Test your function with your four input values by calling it using the following statement:
For example:
print(taskl 1 ("14576567654934") == 2)
Do not use the example provided but create your own. [4]
Task 1.3
A full 15-digit IMEI number can be validated by removing the check digit, calculating the check
digit from the remaining 14 digits and comparing it to the removed digit.
Write a function task1_ 3 (input_ value) that returns a Boolean. The function should:
• validate that the parameter input_ value is either an integer, or a string containing a valid
integer
• check that it is 15 digits in length
• return False if the value received is invalid for any reason
• remove the digit on the right-hand side
• use your function from Task 1.1 to calculate the check digit from the remaining 14 digits
• return a Boolean representing the comparison between the calculated check digit and the
original removed digit. [4]
Test your function with four input values (these may be based on those from Task 1.2 or otherwise),
two should be correct IMEI numbers, two should be in error.
If a value of False is expected to be returned by the comparison, this can be changed to still
output True by using the not keyword, for example:
2 For this question you are provided with three text files, each contains a valid list of positive
integers, one per line:
For each of the sub-tasks, add a comment statement at the beginning of the code using the hash
symbol '#' to indicate the sub-task the program code belongs to, for example:
Output:
Task 2.1
Call your function tas k2 _ 1 with the file TEN. txt, printing the returned list and its length, using
the following statements:
Task 2.2
Call your function task2 _ 2 with the contents of the file TEN. txt, printing the returned list, for
example, using the following statement:
Task 2.3
Call your function task2_ 3 with the contents of the file TEN. txt, printing the returned list, for
example, using the following statement:
Task 2.4
The timei t library is built into Python and can be used to time simple function calls. Example
code is shown in Task2 timing. py. (The sample code assumes that it has access to the
task2 2 function.)
Using the timei t module, or other evidence, and the three text files provided with this question,
compare and contrast, including mention of orders of growth, the time complexity of the insertion
sort and quicksort algorithms. [5]
For each of the sub-tasks, add a comment statement at the beginning of the code using the hash
symbol '#' to indicate the sub-task the program code belongs to, for example:
Output:
Task 3.1
Write the LinkedList class in Python. Use of a simple Python list is not sufficient. Include the
following methods:
• insert (integer_ value) inserts the integer_ value at the beginning (head) of the list
• delete (integer_ value) attempts to delete integer_ value from the list; if the item
was not present, return None
• search (integer_ value) returns a Boolean value: True if integer_ value is in the list,
False if not in the list
• count () should return the number of elements in the list, or zero if empty
• to_ string () should return a string containing a suitably formatted list with the elements
separated by a comma and a space, with square brackets at either end, e.g. in the form:
[11, 2, 7, 4]
[8]
Test LinkedList by using the data in the file Task3data. txt. Use the to_ String () method
to print the resulting contents of the list. [3]
Task 3.2
The insert method in the SortedLinkedList subclass should ensure that the elements are
stored in ascending order. [5]
Test SortedLinkedList by using the data in the file Task3data. txt. Use the to_ String ()
method to print the resulting contents of the list.
Print the result of searching the SortedLinkedList for the value 94. [2]
Task 3.3
Additional enqueue and dequeue methods are to be defined on the Queue class:
• enqueue (integer_ value) will insert integer_ value to the end of the queue
• dequeue () will return the first element in the queue. If the queue is empty, return None. [6]
Test Queue by using the data in the file Task3data. txt. Print the first five elements to be
dequeued from the list. [1]
4 A competition has three qualifying rounds. Competitors could score up to 100 points in each
round. Each competitor has a unique ID number. The competitor's ID, name, and the scores for
each round are held in a database, Task4. db, provided with this question.
• competitor(id , name)
• scores(id, round, score)
Not every competitor competed in all three rounds, but they did all compete in round 1.
Task 4.1
Write a Python program and the necessary files to create a web application. The web application
offers the following menu options:
Round 1 Scores
Round 2 Scores
Round 3 Scores
Mean Scores
Qualifiers
Run the web application and save the output of the program as
Task 4.2
The results of the query should be shown on a web page in a table that:
The resulting web page for each round should be accessed from the corresponding menu option
from Task 4.1.
Run the web application and save the output of the program as
Task4 _ 2_ <your name> <centre number> <index number > 3.html [2]
Task 4.3
• competitor name
• the mean score for each competitor, based on the number of rounds in which they competed.
• lists the name of each competitor and their mean score (to 2 decimal places)
• has the results shown in ascending alphabetical order of the competitor's name.
The resulting web page should be accessed from the corresponding menu option from Task 4.1.
Run the web application and save the output of the program as
Task 4.4
In order to qualify for the final of the competition, competitors need to score over 250, in total, in
the first three rounds.
• competitor's name
• their total score
• whether that competitor has qualified for the final.
The results of the query should be shown on a web page in a table that:
• lists the names of the competitors, their scores and whether they qualified
• has the results shown in descending order of the competitor's score.
The resulting web page should be accessed from the corresponding menu option from Task 4.1.
Run the web application and save the output of the program as
BLANK PAGE
BLANK PAGE
BLANK PAGE
possible. Every
Permission to reproduce items where third-party owned material protected by copyright is Included has been sought and cleared where
included, the
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been
publisher will be pleased to make amends at the earliest possible opportunity.
University of
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the
Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.