SPSS 2018 P2
Uploaded by IDKWHYBUTIAM · 3 November 2024
Preview
Text from the first pagesREAD THESE INSTRUCTIONS FIRST Write your name, class, index number in the spaces at the top of this page. Write in dark blue or black pen. 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. Parent’s Signature : ____________________________ Date: ____________________________ Remarks (if any) : For Examiner’s Use Marks /50 Total % This document consists of 8 printed pages including this page. ST. PATRICK'S SCHOOL PRELIMINARY EXAMINATIONS 2018 SECONDARY 4 EXPRESS NAME CLASS INDEX NUMBER COMPUTING Paper 2 Practical (Lab-based) 7155/02 13 September 2018 2 h 30 min Additional Materials: Electronic version of JOBS.XLSX data file Electronic version of ANALYSIS.PY file Electronic version of ROBOT.PY file Insert Quick Reference Glossary
2 [Turn over 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. 1. Identifiers When naming functions, variables and modules, the following rules must be observed: • Names should begin with character 'a' - 'z' or 'A' - 'Z' or '_' • and followed by alphanumeric characters or '_' • Reserved words should not be used. • User-defined identifiers are case sensitive. 2. Comments and Documentation Strings # This is a comment """ This is a documentation string over multiple lines """ 3. Input/Output print ("This is a string") s = input ("Instructions to prompt for data entry.") 4. Import import <module> e.g. import math 5. Data Type Data Type Notes int integer float real number Bool boolean str string (immutable) list series of values 6. Assignment Assignment Statement Notes a = 1 integer b = c variable d = "This is a string" string mylist = [1, 2, 3, 5, 5] list or array 7. Arithmetic Operators: Operator Notes + - plus, subtract * / multiply, divide % remainder or modulus ** exponential or power // quotient of the floor division 8. Relational Operators: Operator Notes == equality != real number > >= greater than, greater than or equal to < <= less than, less than or equal to 9. Boolean Expression Boolean Expression Notes a and b logical and a or b logical or not a logical not 10. Iteration while loop for loop while condition(s): <statement(s) for i in range(n): <statement(s)> for record in records: <statement(s)>
3 [Turn over 11. Selection Type 1 Type 2 Type 3 if condition(s): <statement(s)> if condition(s): <statement(s)> else: <statement(s)> if condition(s): <statement(s)> elif condition(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() (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 or pass raise return try while with yield
4 [Turn over Task 1 1 2 3 4 5 6 A solutions company uses spreadsheet software to record its jobs details. You are required to finish setting up the spreadsheet. Open the file JOBS. You will see the following data. Save the file as MYJOBS_<Class>_<Class_Index_Number>_<Your_Name> In the Job Code column, enter a function to extract the last 2 letters of the corresponding Job ID. In the Cost column, enter a function to look up the Fees in the Job Code Fees table, add that with the corresponding Hourly Rate, and multiply it by Hours Required, i.e. [Cost = Job Code Fees + (Hourly Rate x Hours)] Format the Cost column to automatically highlight those cells whose total cost is above $50 with a blue background. In the Staff Required table, enter a function in the No. of Staff column to compute the number of staff required for each expertise. Enter “Total Cost” in G14 and bold it. In H14, enter a function to calculate the total cost of all the jobs. Save and close your file. [2] [3] [1] [2] [2]
5 [Turn over Task 2 7 8 The following program analyses a user password consisting of only digits and letters. The program then displays the list of digits and letters in the password. digits = [] letters = [] password = input("Enter the password: ") for index in range(len(password)): if password[index].isdigit(): digits.append(int(password[index])) elif password[index].isalpha(): letters.append(password[index]) print("Digits in the password: ", digits) print("Letters in the password: ", letters) Open the file ANALYSIS.py Save the file as MYANALYSIS_<Class>_<Class_Index_Number>_<Your_Name> Edit the program so that it: (a) Displays the largest digit in the password. (b) Displays the list of uppercase letters. (c) Tests if the user password input is exactly 6 characters in length. If not, the program asks the user for input again with a corresponding error message. Save your program. Save your program as VARANALYSIS_<Class>_<Class_Index_Number>_<Your_Name> Edit your program so that it displays the average of all digits in the password. Save your program. [1] [2] [3] [4]
6 [Turn over Task 3 9 The following program should display the current location of a robot and the distance travelled, after a series of movement instructions by the user. The program asks the user to enter the direction and the number of steps for each move. The program ends when the user types “exit”. The program then displays the current location of the robot and the distance travelled. There are several syntax errors and logical errors in the program. number_steps current_location = [0,0] print("Current location: ", current_location) while True: direction = input("Enter the direction (up, down, left, right). Type exit to end: ") if direction == exit: continue else: number_steps = input("Enter the number of steps to move: ") if direction = "up": current_location[1] += number_steps elif direction == "down": current_location[1] -= number_steps elif direction == "left": current_location[0] += number_steps else if direction == "right": current_location[1] += number_steps print("\nCurrent location: ", current_location) print("Distance travelled: ", round(math.sqrt(current_location[0]**2 + current_location[1]**2),2) Open the file ROBOT.py Save the file as MYROBOT_<Class>_<Class_Index_Number>_<Your_Name> Identify and correct the errors in the program so that it works correctly according to the rules above. Save your program. [10]
7 [Turn over Task 4 You have been asked to write a program to record and analyse the competitive timing of swimmers in the men’s heats of a National Swimming Championship. The program should allow you to: • Enter data in the format a, b, c, d where a, b, c, d are the time taken in seconds by a swimmer to compl
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

