HCI 2025 H2 Computing Prelim Paper 2
Uploaded by Kozak327 · 24 August 2026
Preview
Text from the first pagesThe document consists of 10 pages. HWA CHONG INSTITUTION C2 PRELIMINARY EXAMINATION 2025 COMPUTING Higher 2 25 AUG 2025 Paper 2 (9569 / 02) 1400 – 1700 hrs Additional Materials: Electronic version of APPOITMENT.txt data file Electronic version of CUSTOMER.txt data file Electronic version of STYLIST.txt data file Electronic version of WISHLIST.txt data file Insert Quick Reference Guide READ THESE INSTRUCTIONS FIRST 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. Approved calculators are allowed. Save each task as it is completed. 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 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 100.
2 Instruction to candidates: Your program code and output for each of Task 1 to 4.3 should be saved in a single . ipynb file using Jupyter Notebook. For example, your program code and output for Task 1 should be saved as: TASK1_<your name>_<centre number>_<index number>.ipynb Make sure that each of your .ipynb files shows the required output in Jupyter Notebook. 1 Name your Jupyter Notebook as TASK1_<your name>_<centre number>_<index number>.ipynb The school is exploring an online system to manage student administrative matters. A student account is formed by 6 digits and 1 lower case letter. The last letter is the check digit, and is calculated using the following algorithm based on the 6 digits: 1. Starting from the left, the first digit has position number 1. 2. For digits at odd numbered positions, it carries a weight of the position number. For digits at even numbered positions, it carries a weight double the position number. 3. Calculate the sum of the products of each digit multiplied by its respective weight. 4. Calculate the remainder obtained when the sum is divided by 26. 5. Convert the remainder to the check digit using the conversion table below: Remainder 0 1 2 … 24 25 Check Digit a b c … y z For example, given the 6 digits 987654: Step 1: Digit 9 8 7 6 5 4 Position 1 2 3 4 5 6 Step 2: Weight 1 4 3 8 5 12 Step 3: 9 × 1 + 8 × 4 + 7 × 3 + 6 × 8 + 5 × 5 + 4 × 12 = 183 Step 4: Remainder = 1 Step 5: check digit = b
3 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: In [1]: Output: Task 1.1 A full student account can be validated by calculating the check digit from the first 6 digits and comparing it to the last letter. Write a function task1_1(account) that determines if a student account is valid. The function should: • check that the parameter account consists of 6 digits and 1 lower case letter. Output appropriate messages if the format is invalid. • calculate the check digit and output appropriate messages indicating if the account is valid. Test the function fully with suitable test data. [8] Students must create a password for their account and the strength rating of a password is calculated based on these rules: • Add 1 point for every 2 characters, up to a maximum of 4 points • Add 1 point if the password contains any uppercase letters • Add 1 point if the password contains any lowercase letters • Add 1 point if the password contains any digits • Add 1 point if the password contains any special characters, e.g. @, # • Deduct 1 point if the password contains any repeated consecutive characters, e.g. ‘aa’, ‘111’ For example, ‘HwaChong#25’ adds 4 points based on the length, 1 point each for containing both lower- and upper-case letters, digits and special characters. The total rating is 8. The strength of a password is considered weak if the rating is lower than 3, medium if the rating is between 3 and 5, and strong if the rating is higher than 5. For example, ‘HwaChong#25’ is a strong password. #Task 1.1 Program Code
4 Task 1.2 Write a function task1_2(password) that takes the parameter password and outputs its strength. Test your function using the following three calls: task1_2('cp') task1_2('Password') task1_2('HwaChong#25') [8] Passwords are encrypted before storing for safety reasons. The encryption shifts letters and digits forward by a step size but does not change the special characters. Here is an example on a step size of 9: • The letter ‘H’ is forwarded 9 steps and encrypted as ‘Q’. • The letter ‘c’ is forwarded 9 steps and encrypted as 'l’. • When an uppercase letter goes beyond ‘Z’ it returns to ‘A’. For example, ‘Z’ is encrypted as ‘I’. • When a lowercase letter goes beyond ‘z’ it returns to ‘a’. For example, ‘w’ is encrypted as ‘f’. • The digit 0 is forwarded 9 steps and encrypted as 9. • When a digit goes beyond 9 it returns to 0. For example, 2 is encrypted as 1. For example, ‘HwaChong#25’ will be encrypted as 'QfjLqxwp#14'. Task 1.3 Write a function task1_3(password, size) that takes the password and the step size as parameters and returns the encrypted message. Test your function using the following code: task1_3('HwaChong#25', 9) == 'QfjLqxwp#14' [6] Save your Jupyter Notebook for Task 1.
5 2 Name your Jupyter Notebook as: TASK2_<your name>_<centre number>_<index number>.ipynb An e-commerce platform offers a discount voucher of a fixed amount when a customer spends at least a specified threshold in single purchase. The customer adds items to a wish list with each item represented by a name and a price. The task is to implement a program that assists the customer by providing a sorted list of items from the wish list that meet or exceed the voucher’s minimum spend. 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: In [1]: Output: Task 2.1 Write a function task2_1(filename) that: • reads a text file filename • stores the records as a list of tuples (name, price) • returns the list Display the contents in the file with the following code: print(task2_1(' WISHLIST.txt ')) [4] Task 2.2 Write a function task2_2(lst) that implements the quicksort algorithm which sorts lst, a list of tuples, in ascending order using the second element of each tuple. The function returns a sorted list. Test and display the sorted list with the following code: lst = [( 'a',6), ('b',2), ('c',5), ('d',7), ('e',1)] print(task2_2(lst)) [8] #Task 2.1 Program Code
6 Task 2.3 Write a function task2_3(lst, target) that implements an adapted binary search algorithm that returns the index of the cheapest item in lst with a price equal to or more than target. You may assume that target is equal to or less than the largest price in lst. Test and display the returned value with the following code: lst = [('e',1), ('b',2), ('c',5), ('a',6), ('d',7)] target = 3 print(task2_3(lst, target)) [6] Task 2.4 Write a function generate_Items(lst, item, threshold) that generates a list of items from the wish list that meet or exceed a given threshold, based on item which the customer intends to buy. You may assume that threshold is greater than
Content continues in the PDF. Download PDF
Related notes
- JPJC 2024 JC2 Prelim Paper 2 QPExam Papers · 2024
- JPJC 2024 JC2 Prelim Paper 2 MS v2Exam Papers · 2024
- JPJC 2024 JC2 Year-End Exam H2 Computing Paper 1Exam Papers · 2024
- JPJC 2024 JC2 Year-End Exam H2 Computing Paper 1 Marking SchemeExam Papers · 2024
- 2024 ASR H2 Computing Prelim P1 SolExam Papers · 2024
- 2024 ASR H2 Computing Prelim P1 QnsExam Papers · 2024
- 2025 VJC H2 Computing Prelim Paper 1Exam Papers · 2025
- 2025 VJC H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- 2025 TJC H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- RVHS 2025 H2 Computing Prelim Paper 1Exam Papers · 2025
- RVHS 2025 H2 Computing Prelim Paper 1 SolutionsExam Papers · 2025
- RI 2025 H2 Computing Prelim Paper 1Exam Papers · 2025
- See all H2 Computing notes

