PRELIM CWSS2022 4E 4N Computing P2
Uploaded by IDKWHYBUTIAM · 3 November 2024
Preview
Text from the first pagesCOMMONWEALTH SECONDARY SCHOOL PRELIMINARY EXAMINATION 2022 COMPUTING Paper 2 (Practical) Name: _____________________________________ ( ) Class: ___________ SECONDARY FOUR EXPRESS/NORMAL (ACADEMIC) Monday 29 August 2022 7155/2 1130 – 1400 2 hour 30 mins 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. 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. Name of setter: Mrs Leong Sai Hong This paper consists of 7 printed pages including the cover page. [Turn over
2 Task 1 Commonwealth Hardware Company uses spreadsheet software to keep track of the amount of bonus given to its employees. Open the file HARDWARE.xlsx and you will see the following data. Save the file as MYHARDWARE_<class>_<index_number>_<your name>.xlsx 1. In cells B6 to B16 enter a formula that uses an appropriate function to generate the username for each employee. The username is created by the first n characters of the member’s name where n is a random number between 1 and the length of the name. For example, for employee, Kelly Lee, her username will be Kel if n is 3. [2] 2. In cells D6 to D16, enter a formula that calculates the number of years of service for each employee. [1] 3. Use an appropriate function to search for the Long service award in the Long service award by year table and use it to complete the Long service award column. [2]
3 4. In cells G6 to G16, enter a formula that uses functions to calculate the bonus each employee is to receive based on the following criteria: Long service award Position Bonus ($) Platinum or Gold Manager 5000 Silver Any 500 Any Any 50 [3] 5. In cells G17 enter a formula that uses functions to find the average amount of bonus given out. The average amount must be rounded to 2 decimal places. [2] Task 2 In Singapore, electronic road pricing (ERP) is implemented on various expressways to regulate traffic. Lately there has been a change in the ERP rates at 5 gantries across some expressways. The following program calculates the change in rates of these 5 gantries. for i in range(5): expressway = input("Enter name of gantry:") old = float(input("Enter old rate:")) new = float(input("Enter new rate:")) change = new - old print("Change is",change) Open the file EXPRESSWAY.py Save the file as MYEXPRESSWAY_<class>_<index_number>_<your name>.py 6. Edit the program so that: (a) It works for any number of gantries. The program must display a suitable input message. [1] (b) The name of gantry is accepted if it is made up of only letters and is of a maximum length of 20. A suitable error message must be displayed and the program must loop until the name of the gantry is an input of a maximum of 20 letters. [4] (c) The name of each gantry for which the ERP rate has been increased is stored in a list and then displayed. [4] (d) The total number of gantries which saw an increase in the ERP rate is displayed. [1] Save your program.
4 Task 3 A program asks the user to enter a letter and a sentence. It then converts each character of the sentence into lowercase before searching through the sentence for the letter entered. If the letter is not found, it will display a message to inform the user. Otherwise, it will display the position at which the letter is found in the sentence. It will also give a comment based on the frequency of the occurrence of the letter in the sentence as shown: No. of times letter occurs in the sentence Comment 1, 2 The letter rarely occurs. 3 - 5 The letter occurs some times. 6 or more The letter occurs many times. There are several syntax errors and logical errors in the program. letter = input("Enter a lower case letter to find:") sentence = input("Enter sentence:").islower() frequency = 0 if sentence.find(letter) = 0: print("Letter is found at position:") while sentence.find(letter) != -1: frequency -= 1 sentence = sentence.find(letter) print(idx) sentence = sentence[:idx] + "#" + sentence[idx:] if frequency > 5: print("Letter occurs many times") elif: print("Letter occurs some times") elif: print("Letter occurs rarely") else print("Letter (letter) is not found").format() Open the file OCCUR.py Save the file MYOCCUR_<class>_<index number>_<your name>.py 7. Identify and correct the errors in the program so that it works correctly according to the rules above. [10] Save your program.
5 Task 4 You have been asked to write a program to simulate the sending and receiving of binary data packet on a network. 8. Save your program as ENTERDATA_class>_<index number>_<your name>.py In the same program, write a function enter_data() which asks the user to enter a binary data packet. Output a suitable error message if the binary data packet is not made up of only ‘0’s or ‘1’s. Repeatedly ask the user to re-enter until it does. [3] Sample executions: >>> enter_data() Enter a binary data packet: 0020110 Data packet should consists of only ‘0’s or ‘1’s. Enter a binary data packet: #bn0110 Data packet should consists of only ‘0’s or ‘1’s. Enter a binary data packet: 0011011 0011011 Save your program. 9. Save your program as COUNTONES_<class>_<index number>_<your name>.py In the same program, write a function count_ones(d), which counts the number of ‘1’s in the d argument. [3] Sample executions: >>> count_ones(‘0011101’) 4 >>> count_ones(‘00000000’) 0 Save your program.
6 10. Save your program as ADDBIT_<class>_<index number>_<your name>.py Use the count_ones(d) function to write a function add_bit(d,oddeven), which decides whether to append a ‘1’ or a ‘0’ to the d argument depending on whether the oddeven argument is ‘odd’ or ‘even’ using the following criteria: Number of ‘1’s in the d argument oddeven argument Character to append to the d argument odd ‘odd’ ‘0’ even ‘odd’ ‘1’ odd ‘even’ ‘1’ even ‘even’ ‘0’ [4] Sample executions: >>> add_bit(‘0011101’,’odd’) 00111011 >>> add_bit(‘0011101’,’even’) 00111010 >>> add_bit(‘0000000’,’odd’) 00000001 >>> add_bit(‘0000000’,’even’) 00000000 Save your program. 11. Save your program as CHECKPARITY_<class>_<index number>_<your name>.py Use the count_ones(d) function to write a function check_parity(d,oddeven), which returns True or False based on the oddeven argument and the number of ‘1’s in the d argument: Number of ‘1’s in the d argument oddeven argument Boolean to return odd ‘odd’ True even ‘even’ True odd ‘even’ False even ‘odd’ False [3] Sample executions: >>> check_parity(‘00111010’,’odd’) False >>> check_parity(‘00111010’,’even’) True Save your program.
7 12. Save your program as PARITY_<class>_<index number>_<your name>.py Extend your program by creating a simple user interface. The program should • Request user to enter a binary data packet. • Perform a validation check to ensure that the data packet consists of only ‘1’s or ‘0’s and display error message as necessary. • Request the user to choose the parity system to be used. The user is to enter ‘even’ if an even parity system is to be used and to enter ‘odd’ if an odd parity system is to be used. • Ask the user if he is sending or receiving the data. The user is to enter ‘S’ if he is sending the data and to enter
Content continues in the PDF. Download PDF
Related notes
- SST (for revision practice) 2024 S3 Computing EOY P2 QP_FinalExam Papers · 2024
- Computing o level notes Notes/Practices · 2023
- BVSS Prelim P1 MSExam Papers · 2024
- BVSS Prelim P1 CPExam Papers · 2024
- CWSS Prelim P1 CPExam Papers · 2024
- CWSS Prelim P1 MSExam Papers · 2024
- computing notesNotes/Practices
- SST 2024 Prelim Paper 1 Ans [revised for 2025] Exam Papers · 2024
- SST 2024 Prelim Paper 1 [revised for 2025] Exam Papers · 2024
- [Notes for Computing] All Definitions/ TermsNotes/Practices · 2025
- [Notes for Computing] Heavily Compressed TextbookNotes/Practices · 2025
- All Computing Terms/DefinitionsNotes/Practices · 2025
- See all Computing notes

