CWSS 2020 Computing P2 Solution
CWSS 2020 Computing P2 Solution
for i in range(5):
ID = input("Enter ID: ")
if ID[0] == "S" or ID[0] == "T":
print("Welcome home!")
count_SG += 1
else:
print("Welcome to Singapore!")
8 ID = ''
count_SG = 0
num = int(input("Enter number of entries: "))
for i in range(num):
ID = input("Enter ID: ")
while len(ID)!= 9:
ID = input("Incorrect length. Please enter
again:")
if ID[0] == "S" or ID[0] == "T":
print("Welcome home!")
count_SG += 1
else:
print("Welcome to Singapore!")
new_string = ''
final_string = ''
for j in range(string):
if string[j] == '':
break
else:
new_string = new_string + string[j]
for i in range(len(indx_lst)):
indx_lst[i] = indx_lst[i]
SOLUTIONS
Task 2
(MYVERIFY.py)
ID = ''
count_SG = 0
for i in range(5):
ID = input("Enter ID: ")
if ID[0] == "S" or ID[0] == "T":
print("Welcome home!")
count_SG += 1
else:
print("Welcome to Singapore!")
(NUMVERIFY.py)
ID = ''
count_SG = 0
num = int(input("Enter number of entries: "))
for i in range(num):
ID = input("Enter ID: ")
while len(ID)!= 9:
ID = input("Incorrect length. Please enter again:")
if ID[0] == "S" or ID[0] == "T":
print("Welcome home!")
count_SG += 1
else:
print("Welcome to Singapore!")
Task 3
(LIST.py)
string = input("Enter string: ")
index = input("Enter the index/indices of characters you wish to
extract in a,b,c format: ")
indx_lst = index.split(",")
new_string = ''
final_string = ''
for j in range(len(string)):
if string[j] == ' ':
continue
else:
new_string = new_string + string[j]
for i in range(len(indx_lst)):
indx_lst[i] = int(indx_lst[i])
Task 4
(GRADES.py)
grades = []
dist, credit, passes, fail = 0,0,0,0
while True:
marks = input("Enter the marks for EL, MT, Math and Sci:
").split(' ')
if marks[0] == 'x':
break
else:
validity = True
for i in range(len(marks)):
marks[i] = int(marks[i])
if marks[i] >= 75:
grades.append("D")
elif marks[i] >= 65:
grades.append("C")
elif marks[i] >= 50:
grades.append("P")
else:
grades.append("F")
for k in range(len(grades)):
if grades[k] == "D":
dist +=1
elif grades[k] == "C":
credit +=1
elif grades[k] == "P":
passes +=1
else:
fail +=1
(VERIFYGRD.py)
grades = []
dist, credit, passes, fail = 0,0,0,0
while True:
marks = input("Enter the marks for EL, MT, Math and Sci:
").split(' ')
if marks[0] == 'x':
break
else:
validity = True
if len(marks) == 4:
for i in range(len(marks)):
marks[i] = int(marks[i])
if marks[i] > 100 or marks[i] < 0:
print("Error, marks should be between 0 and 100
inclusive")
validity = False
else:
print("Error, there should only be 4 entries")
validity = False
if validity == True:
for j in range(len(marks)):
if marks[j] >= 75:
grades.append("D")
elif marks[j] >= 65:
grades.append("C")
elif marks[j] >= 50:
grades.append("P")
else:
grades.append("F")
for k in range(len(grades)):
if grades[k] == "D":
dist +=1
elif grades[k] == "C":
credit +=1
elif grades[k] == "P":
passes +=1
else:
fail +=1
(VARYGRD.py)
grades = []
dist, credit, passes, fail = 0,0,0,0
all_pass = False
while True:
marks = input("Enter the marks for EL, MT, Math and Sci:
").split(' ')
if marks[0] == 'x':
break
else:
validity = True
if len(marks) == 4:
for i in range(len(marks)):
marks[i] = int(marks[i])
if marks[i] > 100 or marks[i] < 0:
print("Error, marks should be between 0 and 100
inclusive")
validity = False
else:
print("Error, there should only be 4 entries")
validity = False
if validity == True:
for j in range(len(marks)):
if marks[j] >= dist_mark:
grades.append("D")
elif marks[j] >= cred_mark:
grades.append("C")
elif marks[j] >= pass_mark:
grades.append("P")
else:
grades.append("F")
for k in range(len(grades)):
if grades[k] == "D":
dist +=1
9