TK Study

Past questions › sample-q18b

2025 3 marks Python / code Secure Software Architecture (Year 12) Developing secure code (Python input validation)

NESA HSC Software Engineering Sample Examination + Marking Guidelines (official, 2025)

(b) Write a function in Python that will check whether a username satisfies the rules (the four username rules in 18a). (3 marks)

Marking criteria

3: Correct function in Python to check whether a username satisfies the rules. 2: Partially correct function. 1: Some understanding of the problem and Python.

Sample answer

def validate_username(username): valid = True

 # length check
 if len(username) < 8:
      valid = False
 elif (not username[0].isupper()):
      valid = False
 elif (not username[-2].islower()):
      valid = False
 elif (not username[-1].isdigit()):
      valid = False

 return valid

Question page · Practise and get marked