Skip to content

OCR GCSE · Free tool

OCR GCSE J277 Exam Reference Language Runner

Run OCR GCSE Computer Science J277 Exam Reference Language (ERL) online. Add inputs and see output and line-numbered errors instantly. Free, no sign-up.

OCR J277
main.erl
Ready

J277 Exam Reference Language rules

OCR Exam Reference Language with print/input, = assignment, == comparison and switch/case.
  • Assign with = and compare with == or !=.
  • Output with print(...) and read with input("Prompt").
  • for i = 0 to 9 ... next i; while ... endwhile; do ... until.
  • Strings have .length, .upper, .lower, .left(n), .right(n) and .substring(start, count).

J277 example programs

Every example runs exactly as shown. Open one in the editor to change it and run it again.

Adding up numbers

Reads three numbers with input(), converts them with int() and prints the total.

Input and outputLoops

Open in editor
// Add up three numbers
total = 0
for i = 1 to 3
  number = int(input("Enter a number: "))
  total = total + number
next i
print("Total: " + str(total))
Inputs
4, 5, 6
Output
Total: 15

switch / case

Uses switch with case and default branches to classify a day of the week.

Selection

Open in editor
// Weekend or school day?
day = input("Enter a day: ")
switch day:
  case "Sat":
    print("Weekend!")
  case "Sun":
    print("Weekend!")
  default:
    print("School day")
endswitch
Inputs
Sun
Output
Weekend!

String methods

Shows .length, .upper, .left, .right, .substring and ASC on a word the user enters.

Strings

Open in editor
// String handling with OCR methods
word = input("Enter a word: ")
print("Length: " + str(word.length))
print("Upper: " + word.upper)
print("First 3: " + word.left(3))
print("Last 2: " + word.right(2))
print("Middle: " + word.substring(1, 3))
print("ASCII code of first letter: " + str(ASC(word.left(1))))
Inputs
Computer
Output
Length: 8
Upper: COMPUTER
First 3: Com
Last 2: er
Middle: omp
ASCII code of first letter: 67

Arrays, functions and procedures

Stores scores in an array, then uses a procedure to print them and a function to return the average.

ArraysSubroutines

Open in editor
// Arrays with a function and a procedure
array scores[5]
scores[0] = 56
scores[1] = 71
scores[2] = 48
scores[3] = 90
scores[4] = 65

function average(values)
  total = 0
  for i = 0 to values.length - 1
    total = total + values[i]
  next i
  return total / values.length
endfunction

procedure showAll(values)
  for i = 0 to values.length - 1
    print(str(i) + ": " + str(values[i]))
  next i
endprocedure

showAll(scores)
print("Average: " + str(average(scores)))
Output
0: 56
1: 71
2: 48
3: 90
4: 65
Average: 66

Reading and writing files

Opens names.txt, prints each line until endOfFile(), then creates and writes a new file.

File handlingLoops

Open in editor
// Read every line of a file, then write a log file
myFile = open("names.txt")
while NOT myFile.endOfFile()
  print(myFile.readLine())
endwhile
myFile.close()

newFile("log.txt")
log = open("log.txt")
log.writeLine("Read all names")
log.close()
Output
Ada
Alan
Grace