0% found this document useful (0 votes)
60 views10 pages

SRSS 2020 P2

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)
60 views10 pages

SRSS 2020 P2

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/ 10

SERANGOON SECONDARY SCHOOL

PRELIMINARY EXAMINATION
SECONDARY 4 EXPRESS

CANDIDATE
( ) CLASS
NAME

CENTRE INDEX
S
NUMBER NUMBER

COMPUTING 7155/02
Paper 2 (Lab-based) 26 August 2020
2 hours 30 minutes

Additional Materials: Electronic version of STBANK.xlsx data file


Electronic version of USERNAME.py file
Electronic version of FRUIT.py file
Insert Quick Reference Glossary

Setter(s):

READ THESE INSTRUCTIONS FIRST

Rename the COMPEXAM folder in the thumb drive to <your name>_<centre number>_<index number>.
Retrieve the electronic files from this folder in the thumb drive.
Save your work inside this folder in the thumb drive using the file name given.

Answer all questions.

All tasks must be done in the computer laboratory. You are not allowed to bring in or take any pieces of
work or materials on paper or media in any 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

50

This question paper consists of 9 printed pages and 1 blank page.


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.

2
1. Identifiers 6. Assignment

When naming functions, variables and modules, the Assignment Notes


following rules must be observed: Statement
a=1 integer
Names should begin with character 'a' - 'z' or
'A' - 'Z' or '_'
b=c variable
and followed by alphanumeric characters or '_' d = "This is a string" string
mylist = [1, 2, 3, 5, 5] list or array
Reserved words should not be used.
User-defined identifiers are case sensitive. 7. Arithmetic Operators:

Operator Notes
2. Comments and Documentation Strings + - plus, subtract
* / multiply, divide
# This is a comment % remainder or modulus
"""
** exponential or power
This is a documentation string // quotient of floor division
over multiple lines
""" 8. Relational Operators:

Operator Notes
3. Input/Output == equality
!= not equal to
print ("This is a string") > >= greater than, greater than
or equal to
s = input ("Instructions to prompt for data entry.")
< <= less than, less than or equal
to
4. Import
9. Boolean Expression
import <module>
Boolean Notes
e.g. import math Expression
a and b logical and
a or b logical or
5. Data Type
not a logical not
Data Type Notes
int integer 10. Iteration
float real number
Bool boolean while loop for loop
str string (immutable) while condition(s): for in range(n):
list series of values <statement(s) <statement(s)>
for record in records:
<statement(s)>

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( )


format( )

(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

4
Task 1
A bank uses a spreadsheet software to record the amount of loan for each client. You
are required to finish setting up the spreadsheet to record the lump sum repayment
amount.

Open the file STBANK.xlsx. You will see the following data.

Save the file as STCLIENTS_<your name>_<centre number>_<index number>.xlsx

1. In cell D20 enter a formula to calculate the median amount of all the loans, rounded to [2]
the nearest dollar ($).

2. In cells F4 to F18 enter a formula that uses an appropriate function to indicate the Client [1]
Type (S for privileged clients and C for normal clients) by extracting the first letter from
the Client ID column.

3. In cells G4 to G18 enter a formula that uses an appropriate function to search for the [2]
Interest Rate in the Compound Interest Rate per Year table and use it to complete
the Compound Interest Rate column.

4. In cells H4 to H18 enter a formula that uses an appropriate function to calculate the [2]
lump sum repayment amount for each client.

5
5. 5In cells I4 to I18 enter a formula to calculate the discount for each client. Each privileged [1]
client is given a discount of 10% of the lump sum repayment amount. Otherwise the
discount is 0 (zero).

6. In cells J4 to J18 enter a formula to calculate the Discounted Lump Sum. It is the [1]
Lump Sum Repayment less the Discount.

7. 6In cell I20 enter a formula to count the number of privileged clients. [1]

Save and close your file.

Task 2 begins on the next page.

6
Task 2
The following program creates a username for a user. It creates the username by appending
the name with a series of character ‘0’ (zero) until the length of the username is ten
characters long.

The name entered must be entered without any space, for example, JohnTan.

name = input("Please enter your name: ")

size = len(name)

if size < 10:

username = name + (10-size)*'0'

print("Your username is " + username)

Open the file USERNAME.py

Save the file as MYUSERNAME_<your name>_<centre number>_<index number>

8. Edit the program so that the username is created by appending the name with a series [1]
of character ‘9’ until the length of the username is ten characters long.

9. The program needs to validate the length of the name and whether the name contains
alphabets only.

Save the file as MYUSERNAME2_<your name>_<centre number>_<index number>

(a) Edit the program to:


● test whether the user has entered a name of between three to twenty
characters containing only alphabets
● output a suitable error message that asks the user to re-enter a name again, [4]
and repeat this until the user enters a valid name.

(b) Edit the program to:


● ask the user to enter a single character (‘0’ to ‘9’) to be used for appending
the name with a series of this character until the length of the username is
ten characters long
● output a suitable error message that asks the user to enter a single digit
again, and repeat this until the user enters a valid single digit
● use the first ten characters of the name as the username if the name entered [5]
contains ten or more characters.

Save your program.

7
Task 3
The following program searches a list of fruits sorted in ascending order to check if it is sold
in a shop.

If the fruit is found in the list, a message is displayed on the screen that states the number
of items that are in the list and the position of the fruit in the list. Otherwise, a message is
displayed on the screen that states the fruit is not in the list.

There are several syntax and logical error(s) in the program.

#list of fruits sorted in ascending order


fruits_list = ["apple", "grape", "guava", "mango", "orange", "pear"]
fruit_to_find = input("Which fruit would you like to search for? "
items = length(fruits_list)

found = True
for i in range(item):
if fruits_list[index] == fruit_to_find:
print("There are " + str(items) + " fruits in the list, " +
fruit_to_find + " is item " + str(i) +
" in the list.")
found = True

else fruits_list[i] < fruit_to_find:


break

if found = True:
print("The fruit is not in the list.")

Open the file FRUIT.py

Save the file as MYFRUIT_<your name>_<centre number>_<index number>

10. Identify and correct the errors in the program. [10]

Save your program.

8
Task 4
You have been asked to create a program to generate a check digit.

The program must:

● Allow a user to enter a twelve-digit number. The program must ask for another
twelve-digit number each time the user enters an input that is not a twelve-digit
number.
● Each digit, starting from left to right, is alternately multiplied by the weights 1 or 3
and the results are sum up together.
Example of a twelve-digit : 978030640615
9×1 + 7×3 + 8×1 + 0×3 + 3×1 + 0×3 + 6×1 + 4×3 + 0×1 + 6×3 + 1×1 + 5×3 = 93
● The sum from the previous step is divided by ten to get the remainder.
93 / 10 = 9 remainder 3
● Subtract the remainder from ten to obtain the check digit.
10 – 3 = 7
So 7 is the check digit.
● Display this on the screen. Your output must look like this:

7 is the check digit for the twelve-digit number 978030640615

11. Write your program and test that it works. [10]

Save your program as CD1_<your name>_<centre number>_<index number>.py

12. When your program is working, test it for the following :

Test 1 – User enters the number 97803064061


Test 2 – User enters the number 9780306406157
Test 3 – User enters the number 97803064A615
Test 4 – User enters the number 979861499524
Test 5 – User enters the number 057294690123

Take a screenshot of Test 1, 2 and 3. Save this single screenshot as:


TEST123_<your name>_<centre number>_<index number>

Take a screenshot of Test 4 and 5. Save this single screenshot as:


TEST45_<your name>_<centre number>_<index number> [4]

Save you files in either .png or .jpg format.

13. Save your program as CD2_<your name>_<centre number>_<index number>.py

Extend your program to allow the user to input the weights for both the odd-numbered
and even-numbered digit to be used for the calculation of the check digit.

You are not required to validate the weights. [2]


9
Save your program.

14. Save your program as CD3_<your name>_<centre number>_<index number>.py

Extend your program to allow the user to enter either a twelve-digit or thirteen-digit
number. When the user enters a thirteen-digit number, the right most digit is the check
digit and a suitable message must then be output to indicate whether this check digit
is valid or not.

You are not required to do any additional validation. [4]

Save your program.

END OF PAPER

10

You might also like