0% found this document useful (0 votes)
18 views6 pages

SST 2020 Computing P2 Solution

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

SST 2020 Computing P2 Solution

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2020 SEC 4 COMPUTING PRELIM PAPER 2 MARKING SCHEME

Task 1

Question Answer

1 =SUM(C3:C17)

2 =MAX(C3:C17)-MIN(C3:C17)

3 =C3-D3

[1 mark for correct first entry. 1 mark for all subsequent entries]
4 =VLOOKUP(F3,E$22:F$26,2,TRUE)

[1 mark for correct first entry. 1 mark for all subsequent entries]
5 = -PMT(G3/12,F3*12,E3,0)

[1 mark for correct first entry. 1 mark for all subsequent entries]
6 =IF(AND(E3>=28000,F3<=5),"Yes","No")

[1 mark for correct first entry. 1 mark for all subsequent entries]

1
Task 2

Question Answer Marks


#User sets password and tries to log into a system

#Sets password that consists of at least 8 characters,


#at least 1 upper case letter
# Q9i Able to run Q9 with no errors [1 mark]
# Q10i Able to run Task Q10 with no errors [1 mark]

accept_length = False
accept_uppercase = False
# Q9ii Loop for user to input correct length [1 mark]
# Q10ii Loop for user to input at least one uppercase [1 mark]
while (accept_length == False) or (accept_uppercase == False):
password = input("Please set password: ")
print("Your password is : ", password)
# Q9iii Printing input requirements of 8 characters with correct
condition [1 mark]
if len(password) < 8:
print("Your password should be at least 8 characters long.")
else:
accept_length = True
# Q10iii Correct checking of uppercase characters [1 mark]
for char in password:
if (ord(char) >= 65) and (ord(char) <= 90):
accept_uppercase = True
# Q10iv Printing input requirements of at least one uppercase with
correct condition [1 mark]
if accept_uppercase == False:
print("Your password should consists of at least one uppercase
alphabet.")

#Reverse password
reverse = ""
#Q8i Consider each character in the password [1 mark]
for char in password:
reverse = char + reverse
#Accept password[::-1]
#Q8ii Print the password in reverse [1 mark]
print("The reverse password is : ",reverse)

#Log into system

2
#Q7 Change the count from 3 to 4 [1 mark]
count = 4
hit = False
while count > 0 and hit == False:
print("Please log into the system.")
print("You have {} attempt(s) left.".format(count))
user_input = input("Please enter the password: ")
if user_input == password:
print("You have successfully logged into the system.")
hit = True
else:
print("You did not enter the correct password.")
count -= 1

if count == 0:
print("You are locked out of the system.")

3
Task 3

Question Answer Marks


DS = input("DD MM YYYY:").split()
MM, Yr = int(DS[1]), int(DS[2]) } must individually cast into int, syntax error [1]
leap_yr = False } Uppercase F, syntax error [1]
if (Yr % 4) == 0:
if (Yr % 100) == 0:
if (Yr % 400) == 0:
leap_yr = True
else: leap_yr = True } Indented to 2nd if statement, syntax error [1]

max_day = 31
if MM in [4, 6, 9, 11]: } 9 (Sept) instead of 8(Aug), logic error [1]
max_day = 30
elif MM == 2: } == symbol instead of =, syntax error [1]
max_day = 28
if MM == 2 and leap_yr: } implement check for number of days in leap year
max_day = 29 } logic error [2]

newDD, newMM, newYr = int(DS[0])+14, MM, Yr

if newDD > max_day:


newDD = newDD % max_day } % instead of MOD, syntax error [1]
newMM += 1 newDD = newDD – max_day also accepted
if newMM > 12:
newMM = 1
newYr += 1 } += instead of -=, logic error [1]

print("+14 days\nDD: {} MM: {} YYYY: {} ".format(newDD,newMM,newYr))


} "{}" missing, runtime error [1]

}}

4
Task 4
Question Answer Marks
12 9x possible Output 1 mark each
Using appropriate range for both randint statements.
For-loop to generate N numbers

13 Each correct display 1 mark each

14 Check for Pass / Fail of die roll


Loop to continue program

Sample Code 4.1


import random

#Inputs & Validate


allOk = False
while not allOk:
B, Tn, N, X, C = input("Enter values[B, Tn, N, X, C] : ").split()
if not (B.isdigit() and 0 <= int(B) <= 10):
print("Invalid input")
continue
if not (Tn.isdigit() and 5 <= int(Tn) <= 30):
print("Invalid input")
continue
if not (N.isdigit() and 1 <= int(N) <= 20):
print("Invalid input")
continue
if not (X.isdigit() and X in ["2", "4", "6", "8", "10", "12", "20"]):
print("Invalid input")
continue
if not (C.isdigit() and 0 <= int(C) <= 10):
print("Invalid input")
continue
allOk = True

#Output "1d20 +B, Target Number: Tn" and generate the random value
print("1d20 +{}, Target Number: {}".format(B, Tn))
num = random.randint(1, 20) + int(B)
print("Results\t: {}".format(num))
if num < int(Tn):
print("Fail")
else:
print("Pass")
print("Damage\t: {}d{} +{}".format(N, X, C))
total = 0
print("Result\t: ", end = " ")
for _ in range(int(N)):
temp = random.randint(1, int(X))
print(temp, end = " ")
total += temp
print("\nTotal: {}".format(total+int(C)))

Sample Code 4.3


import random

cont = "Y"

5
while cont != "NO":
#Inputs & Validate
allOk = False
while not allOk:
B, Tn, N, X, C = input("Enter values[B, Tn, N, X, C] : ").split()
if not (B.isdigit() and 0 <= int(B) <= 10):
print("Invalid input")
continue
if not (Tn.isdigit() and 5 <= int(Tn) <= 30):
print("Invalid input")
continue
if not (N.isdigit() and 1 <= int(N) <= 20):
print("Invalid input")
continue
if not (X.isdigit() and X in ["2", "4", "6", "8", "10", "12",
"20"]):
print("Invalid input")
continue
if not (C.isdigit() and 0 <= int(C) <= 10):
print("Invalid input")
continue
allOk = True

#Output "1d20 +B, Target Number: Tn" and generate the random value
print("1d20 +{}, Target Number: {}".format(B, Tn))
roll1 = False
num = random.randint(1, 20)
if num == 1:
roll1 = True
else:
num += int(B)
print("Results\t: {}".format(num))
if num < int(Tn) or roll1:
print("Fail")
else:
print("Pass")
print("Damage\t: {}d{} +{}".format(N, X, C))
total = 0
print("Result\t: ", end = " ")
for _ in range(int(N)):
temp = random.randint(1, int(X))
print(temp, end = " ")
total += temp
print("\nTotal: {}".format(total+int(C)))

print()
cont = input('Enter "NO" to quit, press enter to
continue...').upper()

You might also like