OCR GCSE Computer Science June 2024 Paper 2, Question 6: string manipulation

OCR J277/02 June 2024, Question 6: work out the output of upper, left(4) and int(right(4)) * 2 on the string abcd1234, then write pseudocode that concatenates two words. Worked through, with the Python equivalents to run.

Past paper questionOCR J277/02June 2024 Paper 26 marksRead the code

Question 6 of the OCR GCSE Computer Science Paper 2 sat on 21 May 2024 (J277/02) tests OCR Exam Reference Language string handling. Part (a) asks for the output of three statements (3 marks). Part (b) asks for three lines of pseudocode that join two words (3 marks).

We do not copy the exam paper here. Open it beside this page: OCR June 2024 J277/02 question paper (PDF). When you have finished, check the mark scheme too.

Part (a): the question in short

The variable message holds "abcd1234". The paper shows that print(message.length) outputs 8, and asks for the output of three more statements.

Statement What it does Output
print(message.upper) the whole string in capitals ABCD1234
print(message.left(4)) the first 4 characters abcd
print(int(message.right(4)) * 2) the last 4 characters, cast to an integer, doubled 2468

The last one is three steps from the inside out. message.right(4) is the string "1234". int(...) makes it the number 1234. Times 2 is 2468.

Where the marks are lost in part (a)

  • 12341234. That is what you get if you forget the int. A string times 2 repeats. The cast is there so that the multiplying is arithmetic.
  • Abcd1234. upper changes every letter. Digits are left alone.
  • ABCD for left(4). The original string is not changed by the line before. message is still in lower case, and the case must be right for the mark.

Part (b): join two words

Store "Hello" in word1, store "Everyone" in word2, and concatenate them into message.

word1 = "Hello"
word2 = "Everyone"
message = word1 + word2

One mark for storing both strings, one for the concatenation in the right order, one for storing the result in message.

Where the marks are lost in part (b)

  • A comma. message = word1, word2 is not concatenation, and the mark scheme refuses it. Use +. (& is accepted.)
  • == for storing. Two equals signs compare. One assigns.
  • Adding a space. The question wants "HelloEveryone" exactly. word1 + " " + word2 is a different string.
  • Quotation marks round the variable names. "word1" + "word2" makes the text word1word2.

Run it

Python spells these differently from OCR's reference language, so here they are side by side. The answers are the same.

It prints 8, ABCD1234, abcd and 2468, then HelloEveryone. The last line shows what happens without the int.
The program
from bugbot import *
connect()

message = "abcd1234"
print(len(message))               # message.length
print(message.upper())            # message.upper
print(message[:4])                # message.left(4)
print(int(message[-4:]) * 2)      # int(message.right(4)) * 2

word1 = "Hello"
word2 = "Everyone"
message = word1 + word2
print(message)

print("without int:", "1234" * 2)
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 June 2024 Paper 2 Question 6(a)?

message.upper outputs ABCD1234. message.left(4) outputs abcd. int(message.right(4)) * 2 outputs 2468.

What string methods are in OCR Exam Reference Language?

.length for the number of characters, .upper and .lower to change case, .left(n) and .right(n) for the first or last n characters, and .substring(start, count) for characters from the middle. ASC() and CHR() convert between characters and their codes.

What is the difference between "1234" and 1234?

"1234" is a string of four characters. 1234 is an integer. Multiplying the string by 2 repeats it. Multiplying the integer by 2 gives 2468. int() casts the string to the integer.

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. F1.8 Data types and casting Programming basics
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.