OCR GCSE Computer Science sample Paper 2, Question 4: the username algorithm

OCR J277/02 sample assessment material, Question 4: work out usernames from a flowchart that takes letters from a name, then write an algorithm that builds them differently for teachers and students. Worked through, with the program to run.

Past paper questionOCR J277/02Sample Paper 28 marksWrite a program

Question 4 of OCR's sample assessment material for GCSE Computer Science Paper 2 (J277/02) is about building usernames from names. Two parts are one mark each, and the last is a 6 mark algorithm with selection and string handling.

We do not copy the paper here. Open it beside this page: OCR J277/02 sample question paper and mark scheme (PDF). The mark scheme is in the same document.

The question in short

The first design, shown as a flowchart, takes the first three letters of the first name and the first two of the surname. Tom Ward becomes TomWa.

The updated design: a teacher's username is the last three letters of the surname followed by the first two of the first name. A student's is as before.

Parts (a) and (b)(i)

  • Rebecca Ellis, by the first design: Reb + El = RebEl.
  • Fred Biscuit, as a teacher: the last three letters of Biscuit are uit, and the first two of Fred are Fr: uitFr.

Any case is accepted.

Part (b)(ii): the algorithm (6 marks)

firstName = input("First name")
surname = input("Surname")
role = input("Teacher or student")
if role == "teacher" then
    username = surname.right(3) + firstName.left(2)
else
    username = firstName.left(3) + surname.left(2)
endif
print(username)

The six marks: inputting the first name, surname and role; selection on the role; the last three letters of the surname for a teacher; the first two of the first name added on; the student case as in the flowchart; and concatenation with output. Plain English steps get the same marks.

Where the marks are lost

  • No role input. The program cannot know whether someone is a teacher unless it asks.
  • The wrong end of the surname. Teachers use the last three letters. In Python that is surname[-3:], or surname[len(surname) - 3:].
  • Adding the parts the wrong way round. Surname first for a teacher, first name first for a student.
  • Forgetting the output. The last mark is for concatenating and outputting.

Run it

Type a first name, a surname and a role. Python slices stand in for OCR's .left() and .right().

Rebecca, Ellis, student gives RebEl. Fred, Biscuit, teacher gives uitFr.
The program
from bugbot import *
connect()

firstName = input("First name: ")
surname = input("Surname: ")
role = input("Teacher or student: ")
if role == "teacher":
    username = surname[-3:] + firstName[0:2]
else:
    username = firstName[0:3] + surname[0:2]
print(username)
Put this demo on your own site

Paste it into a school website, Moodle, Google Sites or a blog. More options on the embed page.

Questions

What are the answers to OCR J277 sample Paper 2 Question 4?

Rebecca Ellis is RebEl. Fred Biscuit as a teacher is uitFr. The algorithm inputs the first name, surname and role, and uses an if on the role to build the username from the right pieces of each name.

How do I get the last three characters of a string?

In OCR Exam Reference Language, surname.right(3). In Python, surname[-3:].

How do I get the first three characters of a string?

In OCR Exam Reference Language, firstName.left(3). In Python, firstName[0:3].

More from this paper

Every OCR J277 question we have worked

Learn it step by step

  1. F3.1 String handling Strings, lists and records
  2. F5.2 Flowcharts Algorithms
  3. F2.2 Selection: if Decisions and loops
Open the lessons

This is our own explanation of a published exam question. It is not written or endorsed by OCR, and the question paper and mark scheme remain OCR's copyright. Read them on OCR's site with the links on this page.