SST 2020 Computing P2 Solution
SST 2020 Computing P2 Solution
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
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)
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
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]
}}
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
#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)))
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()