2026 JPJC Computing Prelim P2 final
Uploaded by Kozak327 · 4 October 2026
Preview
Text from the first pages1 Name:____________________________________ Class:____________ JURONG PIONEER JUNIOR COLLEGE JC2 Preliminary Examination 2026 COMPUTING 9569/02 Higher 2 21 August 2026 Paper 2 (Practical) 3 hours Additional materials: Cover Page Electronic version of TASK1.txt Electronic version of STAFF.txt Electronic version of HOUSE.txt Electronic version of aquila.jpg Electronic version of aries.jpg Electronic version of pavo.jpg Electronic version of taurus.jpg Electronic version of ursa.jpg Electronic version of volans.jpg Insert Quick Reference Guide READ THESE INSTRUCTIONS FIRST Answer all the 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 task. The total number of marks for this paper is 100. This document consists of 13 printed pages and 3 blank pages. [Turn over
2 Instructions to candidates: Your program code and output for each of Task 1 to Task 4.3 should be downloaded in one.ipynb file per task. For example, your program code and output for Task 1 should be downloaded as TASK1_<your name>_<your class>.ipynb. 1 Name your Jupyter Notebook as: TASK1_<your name>_<your class>.ipynb. JPMart, a local supermarket chain, is developing an inventory management program to help store managers organise and search for products efficiently. Each product has the following attributes: • productID: INTEGER • name: STRING • price: FLOAT • stockQuantity: INTEGER The system must allow the manager to view, sort, and search the inventory data based on different needs. Task 1.1 Write a function task1_1(filename) that: • takes a string filename which represents the name of a text file • reads in the contents of the text file • stores each line in the text file in a tuple, with each attribute stored using its data type shown above • returns the list of tuples. [3] Call your function task1_1 with the file TASK1.txt, printing the returned list, using the following statements: result = task1_1("TASK1.txt") print(result) [1] Task 1.2 One method of sorting is the bubble sort. Write a function task1_2(list_of_records) that: • takes a list of tuples • implements a bubble sort algorithm to arrange the products in ascending order of their price • returns the sorted list of tuples. [4] Call your function task1_2 with the contents of the file TASK1.txt, printing the returned list, using the following statement: print(task1_2(task1_1("TASK1.txt"))) [1]
3 Task 1.3 Another sorting method is known as quick sort. Write a function task1_3(list_of_records) that: • takes a list of tuples • implements a quick sort algorithm to arrange the products in ascending order of their product ID • returns the sorted list of tuples. [4] Call your function task1_3 with the contents of the file TASK1.txt, printing the returned list, using the following statement: print(task1_3(task1_1("TASK1.txt"))) [1] Task 1.4 Write a program code to declare a recursive function to: • take in a product ID and the sorted list of tuples from Task 1.3 as two of its parameters • implement recursive binary search • return the name, price and stock quantity of the product if found • return "Not Found" if the product ID is not in the list. Write a main() function to: • get user to input the product ID • call the binary search function with the integer value of the product ID • output the result [4] Call the main() function two times to test with the following inputs: Test 1: largest product ID in the list Test 2: one product ID that is not in the list. Show the output of each test. Save your Jupyter Notebook for Task 1. [1] [Turn over
4 2 Name your Jupyter Notebook as: TASK2_<your name>_<your class>.ipynb. You are asked to implement a 2-dimensional game called Treasure Game using Object-Oriented Programming. P . . . . . . T . . . . . B T . . . T . . . . . . The diagram above shows a 5 by 5 grid, which represents the game map. The player starts at the grid position row 0, column 0, which is at the top left-hand corner of the map, as shown in the diagram above. The map contains: • Normal Tile (.) • Treasure (T) • Bomb (B) • Player (P) To complete the challenge, the player must collect all three treasures (by moving to the coordinates of the treasure tiles). If the player touches a bomb, it will lose some lives. The controls are: W A S D where, W - Move Up A - Move Left S - Move Down D - Move Right The base class Tile contains: o the attribute symbol, a character to be displayed to represent the tile o a constructor that takes symbol as parameter to set the attribute o the method get_symbol() that returns the symbol. The Treasure class (a subclass of Tile) contains: o the attribute treasure that is a string description of the treasure o a constructor that takes symbol and treasure as parameters to set the attributes o the method get_treasure() that returns the treasure. The Bomb class (a subclass of Tile) contains: o the attribute damage that is an integer to represent the number of lives the player will lose if player touches the tile o a constructor that takes symbol and damage as parameters to set the attributes o the method get_damage() that returns the value in damage row 0 col 0 row 4 col 4
5 Task 2.1 Write the class definitions for the Tile, Treasure and Bomb classes. [6] Task 2.2 Write the display_grid(grid) function that takes in grid, that is a 2D array of Tile objects, and display the symbols on the Tile objects. [3] Task 2.3 Write the main() function for the game as follows: 1. Create grid, a 2D array that has 5 rows and 5 columns, that contains Tile objects with the symbol '.' 2. Create Treasure, Bomb and player Tile objects, and store them in the respective positions in the 2D array grid according to the information as follows: Object type row, col symbol treasure damage Treasure 1, 2 'T' "Silver key" Treasure 2, 4 'T' "Gold coin" Treasure 3, 3 'T' "Jade pendant" Bomb 2, 3 'B' 1 Tile 0, 0 'P' 3. Call the display_grid function from Task 2.2 to display the grid. 4. Create suitable variables and initialise them accordingly so that the player starts at the top-left corner of the grid, has an empty inventory list, and has one life. 5. Prompt the user to enter a sequence of moves (W/A/S/D) and store as a string. 6. For each move in the sequence of moves, a. Use the representation below to compute the new location: • 'W' moves up • 'A' moves left • 'S' moves down • 'D' moves right b. If the new location lies within the boundaries of the 2D grid, i. update the player’s row and column variables to the new location, and access the symbol stored in the corresponding cell. ii. If the symbol is B, reduce the player lives according to the damage value of the Bomb object. iii. Else if the symbol is T, add the treasure of the Treasure object to the player inventory list, provided there is no duplicate treasure in the inventory. Ignore any move that goes outside the grid. [Turn over
6 7. At the end of
Content continues in the PDF. Download PDF
Related notes
- NYJC 2026 Prelim P2Exam Papers · 2026
- NYJC 2026 Prelim P1Exam Papers · 2026
- DHS 2026 Y6 H2 Computing Prelim Paper 2_finalExam Papers · 2026
- ACJC 2026 JC2 Computing Prelim Paper 2 (Practical)Exam Papers · 2026
- 2026_NJC Prelim_Computing_P2.pdfExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_markschemeExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_finalExam Papers · 2026
- 2026 ACJC Prelim Computing Paper 2Exam Papers · 2026
- 2024 ACJC Computing PromoExam Papers · 2024
- 2023 ACJC Promo QPExam Papers · 2023
- 2022 ACJC Computing Promo Paper 2Exam Papers · 2022
- 2021 ACJC Computing Promo Paper 2Exam Papers · 2021
- See all H2 Computing notes

