TK Study

Software Engineering › Past questions › Python / code

Past questions: Python / code

6 questions.

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

NESA 2025 HSC Software Engineering exam (online) - Marking Guidelines

In an organisation, temporary passwords are automatically generated for new user accounts. Each password is created from the first three letters of the username followed by '123'. For example, the username 'NESA' will have the password 'NES123'. When a user logs in for the first time, they are asked for their username and password. They receive a welcome message or an error message, depending on whether the password entered follows the rules of new user accounts. Write a Python program that asks a new user for their username and password, and then checks whether the password rule has been followed. (3 marks)

Marking criteria

3: Correct code for the problem. 2: Partially correct code that includes a correct selection structure OR password creation. 1: Some understanding of the scenario and Python.

Sample answer

uName = input('What is your username?') password = input('What is your password?') passwordP1 = uName[:3] passwordP1= passwordP1 + '123' if passwordP1 == password: print ('Welcome!') else: print ('Incorrect password entered')

Question page · Practise and get marked

2025 5 marks Python / code The Software Engineering Project (Year 12) Design, construct and implement a solution (Python)

NESA 2025 HSC Software Engineering exam (online) - Marking Guidelines

[Exact question wording is not published as a paper (online exam). Task as shown by the NESA marking guidelines/mapping grid: Python program: generate 15 unique random numbers from 1 to 25 and print a 5 by 5 grid, with an X in each grid position whose number is in the list and a blank otherwise. Task inferred from the MG sample answer; the exact stem is not published as text]

Marking criteria

5: Correct Python program that creates a list of unique randomly generated numbers; processes the list correctly; uses selection and looping structures; provides correctly formatted output; uses inbuilt Python functions. 4: Substantially correct, most requirements. 3: Some requirements. 2: One requirement. 1: Some understanding of the problem.

Sample answer

import random

randList = [] for x in range(15): nextInt = random.randint(1,25) while nextInt in randList: nextInt = random.randint(1,25) randList.append(nextInt)

pos = 0 while pos < 25: if pos in randList: print ("| X", end=" ") else: print ("| ", end=" ") pos = pos + 1 if (pos % 5 == 0): print("| \n")

Question page · Practise and get marked

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

2025 5 marks Python / code The Software Engineering Project (Year 12) Python: subroutines, lists, loops

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

At a school each student studies five subjects; five periods each day; each period is a different subject; the subject shifts to a different period each day so each subject appears in all five periods during the week. Example: Monday P1 English, P2 Software, P3 Drama, P4 Science, P5 Sport; Tuesday P1 Sport, P2 English, ... Write a Python program (using subroutines) that prints the timetable as: Monday / Period 1: English / Period 2: Software ... for all five days. Start with: subjects = ["English", "Software", "Drama", "Science", "Sport"]. Different students may study different subjects; the program will be used by changing the first line only. (5 marks)

Marking criteria

5: Substantially correct Python program that places each subject in the correct period; displays all 5 days; provides appropriate subroutines; programmatically builds the timetable. 4: Most requirements. 3: Some requirements. 2: One requirement. 1: Some understanding.

Sample answer

subjects = ["English", "Software", "Drama", "Science", "Art"] NUM_DAYS = 5 NUM_PERIODS = 5 DAYS_OF_WEEK = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

def create_timetable(subjects): timetable = [] for day in range(NUM_DAYS): periods = [] for period in range(NUM_PERIODS): periods.append(subjects[(period - day) % NUM_PERIODS]) timetable.append(periods) return timetable

def print_timetable(timetable): print() for day in range(NUM_DAYS): print(f"{DAYS_OF_WEEK[day]}") for period in range(NUM_PERIODS): print(f"\tPeriod {period+1}: {timetable[day][period]}") print()

timetable = create_timetable(subjects) print_timetable(timetable)

Question page · Practise and get marked

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

NESA 2025 HSC Software Engineering Familiarisation Questions - Marking Guidelines (official, 12 June 2025)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: a Python function that checks whether a username satisfies given rules (stem not available)]

Marking criteria

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

Sample answer

def validateUsername(username):

  # Length check
  if len(username) > 8:
      return False

  # Alpha character only check
  elif username.isalpha() == False:
      return False

  # < character check
  elif "<" in username:
      return False

  # If we reach here then the username meets the requirements
  return True

Question page · Practise and get marked

2025 6 marks Python / code The Software Engineering Project (Year 12) Python: lists, loops, selection

NESA 2025 HSC Software Engineering Familiarisation Questions - Marking Guidelines (official, 12 June 2025)

[Question stem not available as text (it is on the interactive NESA familiarisation site). Task per the NESA mapping grid: Python program to display a player's scores and points per round from a list of 10 scores, with bonus points when a round scores 5 (add the next round's score) and a final-round rule (10 points), then the total]

Marking criteria

6: Substantially correct solution with ALL of: looping correctly; referring to the contents of the data structure correctly; displaying the player's scores and corresponding points as shown; calculating the total points; taking bonus points into account; handling the final round correctly. 5: Most features. 3-4: Some features. 2: One feature. 1: Some understanding.

Sample answer

Input code

scores = [3,5,5,2,1,4,0,1,4,5]

Display the scores and points

Header row

print("Round\tScore\tPoints") totalPoints = 0

Calculate the points and print

for i in range(len(scores)): roundNumber = i + 1 score = scores[i] points = score

# Check if any bonuses apply and NOT the final round
if points == 5 and i != 9:
    # Add the points from the next round as bonus points
    points += scores[i + 1]

# Check if the final round bonus applies
if points == 5 and i == 9:
    # Give the bonus points of 10
    points = 10

# Add to the total points tally
totalPoints += points

# Print the results
print(str(roundNumber) + "\t" + str(score) + "\t" + str(points))

print("\nTOTAL POINTS: " + str(totalPoints))

Question page · Practise and get marked