2021 NASS Computing P2 Solutions
Uploaded by IDKWHYBUTIAM · 3 November 2024
Preview
1 Sec 4E Computing Prelim 2021 Paper 2 Marking Scheme Task 1:
2
3 Task 2: total_cost = 0 while total_cost < 3: ##Qn9 toppings = ['ham', 'cheese', 'lettuce', 'tomatoes','capsicum'] # top_cost = [1, 0.8, 0.5, 0.5, 0.8] #Qn8 health = [-1, -0.5, 3, 2.5, 3.2] ####Qn11 print("Welcome to All-Health Salad Bar!") print("Please select your toppings below.") ham = int(input("Quantity of ham: ")) cheese = int(input("Quantity of cheese: ")) lettuce = int(input("Quantity of lettuce: ")) tomatoes = int(input("Quantity of tomatoes: ")) capsicum = int(input("Quantity of capsicum: ")) #Qn8 total_cost = ham*top_cost[0] + cheese*top_cost[1] + lettuce*top_cost[2] + tomatoes*top_cost[3] + capsicum*top_cost[4] #Qn8 if total_cost < 3: ## print("Your order must be at least $3.") ##Qn9 health_score = ham*health[0] + cheese*health[1] + lettuce*health[2] + tomatoes*health[3] + capsicum*health[4] if health_score > 10: #### discount = 1 ####Qn11 print("Total cost: $", total_cost-discount) ####Qn11 if total_cost > 5: ###Qn10 print("You are entitled to a free drink.") ###Qn10
4 Task 3: lower = input("Enter the lower limit: ") #int upper = input("Enter the upper limit: ") #int for num in range(lower,upper): #upper +1 factorial = 0 #1 factor = num for k in range(factorial): # factor factorial *= factor factor += 1 # -= j = factorial total = 0 i = j while i >10: # >= total += i/10 # % i = i//10 total += i if j % total = 0: # == print(str(num)+"! =", j, "is a harshad number.") if str(j) == str(j)[::1]: # -1 print("Factorial of", num, "is palindromic as well!") else # : print("Factorial of", num, "is NOT a harshad number.")
5 Task 4: batches = 5 raw_info = [] batch_no = 0 #[1] for i in range(batches): #[1] batch_no = i+1 prompt = "Info for batch " + str(batch_no) + ": " #[1] raw_info += [input(prompt)] #[1] batch_info = [] for j in range(batches): batch_info += raw_info[j].split(",") #[1] defect = 0 normal = 0 for k in range(len(batch_info)): #[1] if batch_info[k] == "1": normal += 1 #[1] elif batch_info[k] == "0": defect += 1 #[1] print("The percentage of defects is", defect/len(batch_info)*100, "%") #[1] ############################################################## batches = 5 raw_info = [] batch_no = 0 for i in range(batches): batch_no = i+1 prompt = "Info for batch " + str(batch_no) + ": " raw_info += [input(prompt)] ### done = 0 while done != 20: #[1] if len(raw_info[i]) == 19: #[1] done += 1 for m in range(19): #[1] if m % 2 == 0:
6 if raw
Content continues in the 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

