HCI 2025 H2 Computing Prelim Paper 2 Solution
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 b e 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 s t r e n g t h . 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 characte rs. 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 # Task 1.1 def task1_1(account): if len(account) != 7: # check if length is 7 print('Invalid format! Length must be 7!') elif not account[-1].islower(): # check lowercase letter print('Invalid format! The last character must be a lower case letter!') elif not account[:-1].isdigit(): # check six digits print('Invalid format! First six characters must be digits!') else: total = 0 for index in range(6): if index % 2 == 0: # weights differ by index total += int(account[index]) * (index + 1) else: total += int(account[index]) * (index + 1) * 2 remainder = total % 26 # convert remainder to check digit and output messages letters = 'abcdefghijklmnopqrstuvwxyz' if account[-1] == letters[remainder]: print('Valid account!') else: print('Invalid account! Wrong check digit!') # invalid format task1_1('987B65b') task1_1('987654B') task1_1('98765b') # correct and wrong check digit task1_1('987654b') task1_1('987654c') Invalid format! First six characters must be digits! Invalid format! The last character must be a lower case letter! Invalid format! Length must be 7! Valid account! Invalid account! Wrong check digit! # Task 1.2 def task1_2(password): rating = min(4, len(password) // 2) # points by length upper = False lower = False digit = False special = False repeat = False pre_char = '' for char in password: # check if the password contains certain characters if char.isupper(): upper = True elif char.islower(): lower = True elif char.isdigit():
6 digit = True else: special = True if char == pre_char: # check repeat repeat = True pre_char = char # calculate rating rating = rating + upper + lower + digit + special - repeat # output strength if rating < 3: print('Weak') elif rating <= 5: print('Medium') else: print('Strong') task1_2('c
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

