Sec 4 Computing 2020 Prelim Paper 2
Marking Scheme
Task 1:
Task 2:
num_inputs = int(input("Enter the number of sets of data to be
cateogorised: ")) # 2c[1]
for i in range(num_inputs): # 2c[1]
systolic = int(input("Enter your systolic pressure (mmHg): "))
diastolic = int(input("Enter your diastolic pressure (mmHg): "))
cat = None
result = ["Normal BP", "High-normal BP", "Stage 1 Hypertension",
"Stage 2 Hypertension", "Isolated Systolic Hypertension"] # 2b[1]
print("Your BP is", systolic, "/", diastolic, "mmHg.") # 2a[1]
if systolic < 120 and diastolic < 80:
cat = 0
if (systolic >= 120 and systolic <= 139) or (diastolic >= 80 and
diastolic <= 89):
cat = 1
if (systolic >= 140 and systolic <= 159) or (diastolic >= 90 and
diastolic <= 99):
cat = 2 # 2b[2]
if systolic >= 160 or diastolic >= 100:
cat = 3 # 2b[2]
if systolic > 140 and diastolic < 90:
cat = 4 # 2b[2]
print("Diagnosis:", result[cat])
Task 3
all_hashes = ["#gogreen#recycling#upcycling",''
"#coolgames#experiment#expertmode#awesomegames",''
"#diycook#ironchef",''
"#outdoor#fauna#flora#nature#scenery#sunset",''
"#magic#howcanitbe"]
views = [230, 683, 388, 597, 127]
post_titles = ["My Upcycling Project", ''
"Stanley's Awesome Games", ''
"Chef @ Home", ''
"An afternoon at Bukit Timah Reserve", ''
"Card Tricks"] #1 Missing ]
num_hashes = []
for i in range(5): #2 Missing :
num_hashes += [len(all_hashes[i].split("#")) - 1]
#3 Typecast []
highest_hash = max(num_hashes)
index = None
for j in range(5):
if num_hashes[j] == highest_hash: #4 == not =
index = j
#5 index instead of j
print(post_titles[index],"has",highest_hash,"hashtags which is
the highest among all posts.")
average = sum(num_hashes) / 5 #6 / instead of %
print("The average number of hashtags is", average)
#7 average instead of sum
highest_view = max(views) #8 views instead of view
index = None
for k in range(5): #9 5 instead of 4
if views[k] == highest_view:
index = k #10 index = k instead of the other way
print(post_titles[index],"has",highest_view,"views which is the
highest among all posts.")
Task 4
11)
receipt = input("Enter your receipt number: ")
#[1] Initialize receipt and mobile
while len(receipt) != 9 or receipt[:4] != "DRAW" or
receipt[4:].isdigit()==False:
receipt = input("Enter your receipt number: ")
#[2] Data validation of receipt
mobile = input("Enter your mobile phone number: ")
while len(mobile) != 8 or mobile.isdigit()==False:
mobile = input("Enter your mobile phone number: ")
#[2] Data validation of mobile
prize_lst = ["a 65-inch television", "a $50 shopping voucher",
"a $10 shopping voucher", "a recylable bag"]
available = [1, 20, 50, 999999]
#[1] Initialize prize list and availability
import random
prize = random.randint(0,3)
#[1] Generate random number
while available[prize] == 0:
prize = random.randint(0,3)
#[1] Choose random prize
available[prize] -= 1
#[1] Deduce prize balance
print("Congratulations! You have won", prize_lst[prize])
#[1] Display prize won
12) [4] for the 2 screenshots with correct data entered
Test Output 1:
Enter your receipt number: DR12345
Enter your receipt number: DRAW12345
Enter your mobile phone number: 12349876
Congratulations! You have won a <depending on random prize>
Test Output 2:
Enter your receipt number: DRAW23012
Enter your mobile phone number: 98123
Enter your mobile phone number: 98123456
Congratulations! You have won a <depending on random prize>
13)
if prize == 0: #[1] 1st conditional statement
print("Please double-check if your mobile number is",
mobile)
#[1] String concatenation and print
reply = input("Enter 1 to confirm and 0 to re-input your
mobile number: ")
#[1] Ask user for input to confirm
if reply == "1": #[1] 2nd conditional statement
print("You will be informed shortly through your mobile
number.")
#[1] Respond if confirm
elif reply == "0":
mobile = input("Please re-enter your mobile number: ")
print("You will be informed shortly through your mobile
number.")
#[1] Request user to reenter