SST 2022 S4 Computing Prelim P2 Ans
Uploaded by IDKWHYBUTIAM · 3 November 2024
Preview
1 2022 SEC 4 COMPUTING PRELIM PAPER 2 MARKING SCHEME Task 1 Question Answer 1 =MEDIAN(B3:B12) Question Answer 2 =SUMIF(C3:C12,">=10",B3:B12) Question Answer 3 =B3*C3 Question Answer 4 =SUM(D3:D12) Question Answer 5 =MATH.FLOOR(D3) Question Answer 6 =IF(COUNTIF(B$19:F$19,A3)=1,HLOOKUP(A3,B$19:F$20,2,FALSE),"1") Question Answer 7
2 Task 2 Question Answer 8 Input of list_length from user, including input message. list_length = int(input("Please input the length of the list: ") for i in range(list_length): Question Answer 9 Flip the inequality sign in the function. if arr[p] < arr[p+1]: Question Answer 10 Looping the input. Checking if input is numeric using .isdigit() or equivalent. Checking for possibility of negative sign in the first index Shifting the typecasting to int from the input line to the line where valid input is added to the list Error message if input is not valid while True: num = input("Please input an integer: ") if num.isdigit() or (num[0] == "-" and num[1:].isdigit()): arr = arr + [int(num)] break else: print("Invalid input!") Question Answer 11 Looping through the list Comparing the numbers in the list Removing duplicate numbers OR Adding non-duplicate numbers to a second list -1m if all this is not done in UDF #after the list has been sorted in the UDF arr2 = [arr[0]] i = 1 while i < len(arr): if arr[i] != arr[i-1]: arr2 = arr2 + [arr[i]] i += 1
3 Sample Code: list_length = int(input("Please input the length of the list: ")) def bubblesort(arr): for r in range(1, list_length): for p in range(0, list_length - r): if arr[p] < arr[p+1]: #flip the inequality sign arr[p], arr[p+1] = arr[p+1], arr[p] arr2 = [arr[0]] i = 1 while i < len(arr): if arr[i] != arr[i-1]: arr2 = arr2 + [arr[i]] i += 1 return arr2 arr = [] for i in range(list_length): while True: num = input("Please input an integer: ") if num.isdigit() or (num[0] == "-" and num[1:].isdigit()): arr = arr + [int(num)] break else: print("Invalid input!") print("The sorted list:", bubblesort(arr))
4 Task 3 Question Answer 12 print('Welcome to Buttercup Customised Bouquets!') print('Enter up to three flowers to create your bouquet.') flowers = ['red roses', 'pink roses', 'buttercups', "baby's breath", 'limonium'] #syntax: inverted commas prices = [7, 9, 10, 3, 5] counter = 0 cost = 5 #logic: including a base cost of 5 while counter < 3: #logic: while instead of if flower = input('Please choose a flower: ') flower = flower.lower() #logic: lower instead of islower if flower not in flowers: print('Sorry, we do not have that flower. Please try again!') continue #syntax: missing indent flower_index = flowers.index(flower) cost += prices[flower_index] #logic: flower_index instead of flower_index+1 cou
Content continues in the PDF.
Related notes
- 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

