ST.
PATRICK'S SCHOOL
PRELIMINARY EXAMINATIONS 2018
SECONDARY 4 EXPRESS
NAME
CLASS INDEX
NUMBER
COMPUTING 7155/02
Paper 2 Practical (Lab-based) 13 September 2018
2 h 30 min
Additional Materials: Electronic version of JOBS.XLSX data file
Electronic version of ANALYSIS.PY file
Electronic version of ROBOT.PY file
Insert Quick Reference Glossary
READ THESE INSTRUCTIONS FIRST
Write your name, class, index number in the spaces at the top of this page.
Write in dark blue or black pen.
Answer all questions.
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.
Programs are to be written in Python.
Save your work using the file name given in the question as and when necessary.
The number of marks is given in brackets [ ] at the end of each question or part question.
The total number of marks for this paper is 50.
For Examiner’s Use
Parent’s Signature : ____________________________
Date: ____________________________ Marks
/50
Remarks (if any) : Total
This document consists of 8 printed pages including this page.
2
Quick Reference for Python
This quick reference shows some examples of the Python language constructs. The complete Python
language is not limited to these examples.
1. Identifiers 6. Assignment
When naming functions, variables and Assignment Statement Notes
modules, the following rules must be a=1 integer
observed: b=c variable
d = "This is a string" string
• Names should begin with character 'a' - mylist = [1, 2, 3, 5, 5] list or array
'z' or 'A' - 'Z' or '_'
• and followed by alphanumeric 7. Arithmetic Operators:
characters or '_'
• Reserved words should not be used. Operator Notes
• User-defined identifiers are case + - plus, subtract
* / multiply, divide
sensitive. % remainder or modulus
** exponential or power
// quotient of the floor division
2. Comments and Documentation Strings
# This is a comment 8. Relational Operators:
""" Operator Notes
This is a documentation == equality
string over multiple lines != real number
""" > >= greater than, greater than or
equal to
3. Input/Output < <= less than, less than or equal to
print ("This is a string")
9. Boolean Expression
s = input ("Instructions to prompt for data
entry.") Boolean Expression Notes
a and b logical and
a or b logical or
4. Import not a logical not
import <module>
10. Iteration
e.g. import math
while loop for loop
while condition(s): for i in range(n):
5. Data Type
<statement(s) <statement(s)>
Data Type Notes for record in records:
int integer <statement(s)>
float real number
Bool boolean
str string (immutable)
list series of values
[Turn over
3
11. Selection
Type 1 Type 2 Type 3
if condition(s): if condition(s): if condition(s):
<statement(s)> <statement(s)> <statement(s)>
else: elif condition(s):
<statement(s)> <statement(s)>
else:
<statement(s)>
12. Built-in functions
(a) Basic functions
abs( ) chr() float() input() int()
ord( ) print( ) range( ) round( ) str( )
format( )
(b) Mathematical functions
ceil() exp() fabs() floor() log()
max() min() pow() sqrt() trunc()
(c) String functions
endswith( ) find() isalnum() isalpha() isdigit()
islower( ) isspace( ) isupper( ) len( ) lower( )
startswith( ) upper( )
13. Reserved Words
Reserved words cannot be used as identifiers. They are part of the syntax of the language.
False None True and as
assert break class continue def
del elif else except finally
for from global if import
in is lambda nonlocal not
or pass raise return try
while with yield
[Turn over
4
Task 1
A solutions company uses spreadsheet software to record its jobs details. You are required
to finish setting up the spreadsheet.
Open the file JOBS. You will see the following data.
1 Save the file as MYJOBS_<Class>_<Class_Index_Number>_<Your_Name>
2 In the Job Code column, enter a function to extract the last 2 letters of the corresponding
[2]
Job ID.
3 In the Cost column, enter a function to look up the Fees in the Job Code Fees table, add
that with the corresponding Hourly Rate, and multiply it by Hours Required, i.e. [Cost = Job
Code Fees + (Hourly Rate x Hours)] [3]
4 Format the Cost column to automatically highlight those cells whose total cost is above $50
with a blue background. [1]
5 In the Staff Required table, enter a function in the No. of Staff column to compute the
number of staff required for each expertise. [2]
6 Enter “Total Cost” in G14 and bold it. In H14, enter a function to calculate the total cost of all
the jobs. [2]
Save and close your file.
[Turn over
5
Task 2
The following program analyses a user password consisting of only digits and letters. The
program then displays the list of digits and letters in the password.
digits = []
letters = []
password = input("Enter the password: ")
for index in range(len(password)):
if password[index].isdigit():
digits.append(int(password[index]))
elif password[index].isalpha():
letters.append(password[index])
print("Digits in the password: ", digits)
print("Letters in the password: ", letters)
7 Open the file ANALYSIS.py
Save the file as MYANALYSIS_<Class>_<Class_Index_Number>_<Your_Name>
Edit the program so that it:
(a) Displays the largest digit in the password. [1]
(b) Displays the list of uppercase letters. [2]
(c) Tests if the user password input is exactly 6 characters in length. If not, the program
asks the user for input again with a corresponding error message. [3]
Save your program.
8 Save your program as VARANALYSIS_<Class>_<Class_Index_Number>_<Your_Name>
Edit your program so that it displays the average of all digits in the password. [4]
Save your program.
[Turn over
6
Task 3
The following program should display the current location of a robot and the distance
travelled, after a series of movement instructions by the user.
The program asks the user to enter the direction and the number of steps for each move.
The program ends when the user types “exit”. The program then displays the current
location of the robot and the distance travelled.
There are several syntax errors and logical errors in the program.
number_steps
current_location = [0,0]
print("Current location: ", current_location)
while True:
direction = input("Enter the direction (up, down, left, right).
Type exit to end: ")
if direction == exit:
continue
else:
number_steps = input("Enter the number of steps to move: ")
if direction = "up":
current_location[1] += number_steps
elif direction == "down":
current_location[1] -= number_steps
elif direction == "left":
current_location[0] += number_steps
else if direction == "right":
current_location[1] += number_steps
print("\nCurrent location: ", current_location)
print("Distance travelled: ",
round(math.sqrt(current_location[0]**2 + current_location[1]**2),2)
Open the file ROBOT.py
9 Save the file as MYROBOT_<Class>_<Class_Index_Number>_<Your_Name>
Identify and correct the errors in the program so that it works correctly according to the rules
above. [10]
Save your program.
[Turn over
7
Task 4
You have been asked to write a program to record and analyse the competitive timing of
swimmers in the men’s heats of a National Swimming Championship.
The program should allow you to:
• Enter data in the format a, b, c, d where a, b, c, d are the time taken in seconds by a
swimmer to complete a 100-metre race in the butterfly, backstroke, breaststroke and
freestyle categories respectively. An example is 54.42, 56.00, 64.25, 51.01
• Only allow data entry of timing between 40.00 seconds to 70.00 seconds inclusive for
any of the 100-metre categories.
• Calculate the projected 400-metre individual medley timing of the swimmer by taking the
sum of the swimmer’s race timing across all four 100-metre categories.
• Repeat this for a total of seven swimmers.
• Find the average swimmer race timing, rounded off to two decimal places, for each of the
100-metre categories.
• Determine the champion for each of 100-metre categories.
• Display this on the screen. Your output must look like this:
Category Ave Timing Champion Champ Timing
Butterfly 57.32 Swimmer 5 53.53
Backstroke 55.47 Swimmer 2 53.20
Breaststroke 63.00 Swimmer 5 59.88
Freestyle 54.28 Swimmer 1 51.01
Projected 400-metre Individual Medley Timing
Swimmer 1 225.68
Swimmer 2 226.91
Swimmer 3 234.54
Swimmer 4 240.12
Swimmer 5 219.04
Swimmer 6 221.83
Swimmer 7 242.42
10 Write your program and test that it works.
Save your program as HEATS1_<Class>_<Index_Number>_<Your_Name> [10]
11 When your program is working, use the following test data to show your test results:
54.42, 56.00, 64.25, 51.01
58.02, 53.20, 61.33, 54.36
60.12, 54.23, 62.16, 58.03
59.20, 58.34, 66.20, 56.38
53.53, 54.01, 59.88, 51.62
55.46, 53.43, 60.77, 52.17
60.51, 59.11, 66.39, 56.41
Take a screen shot of your results and save it as a bitmap
HEATSRESULTS_<Class>_<Index_Number>_<Your_Name> [3]
[Turn over
8
12 Save your program as HEATS2_<Class>_<Index_Number>_<Your_Name>
Extend your program to allow race timing entered to be “-” if a swimmer happens
not to be participating one or more of the 100-metre category, and if so, that
particular swimmer would not have the projected 400-metre individual medley timing.
Use the following to show your test results:
54.42, 56.00, 64.25, 51.01
58.02, -, -, 54.36
-, 54.23, -, 58.03
59.20, -, -, 56.38
53.53, 54.01, 59.88, 51.62
55.46, 53.43, 60.77, 52.17
60.51, 59.11, 66.39, 56.41
Your output must look like this:
Category Ave Timing Champion Champ Timing
Butterfly 56.86 Swimmer 5 53.53
Backstroke 55.36 Swimmer 6 53.43
Breaststroke 62.82 Swimmer 5 59.88
Freestyle 54.28 Swimmer 1 51.01
Projected 400-metre Individual Medley Timing
Swimmer 1 225.68
Swimmer 2 -
Swimmer 3 -
Swimmer 4 -
Swimmer 5 219.04
Swimmer 6 221.83
Swimmer 7 242.42 [5]
13 Save your program as HEATS3_<Class>_<Index_Number>_<Your_Name>
A swimming competition would only be held if there are at least four participants.
Extend your program to ensure that there are at least four participating swimmers.
Save your program. [2]
End of Paper