Time allowed: 45 minutes
| Centre number |
| | | |
|
Candidate number |
| | | |
| First name |
|
Last name |
INSTRUCTIONS
- Use black ink.
- Answer all the questions.
INFORMATION
- The total mark for this paper is 37.
- The marks for each question are shown in brackets [ ].
Turn over
Section A: Low-Frequency "Ghost Topics"
1
A programmer uses a local variable
temp inside a function called
calculateAverage().
(a) State what is meant by the 'scope' of a variable.
[1]
(b) Explain
two advantages of using local variables rather than global variables.
[4]
2
The J277 specification requires the use of records to store data.
A car dealership uses a record structure called
Car to store data about vehicles.
The fields are:
ID (Integer),
Make (String), and
Price (Real).
(a) Write the OCR Exam Reference Language (ERL) or Python-style code to define this record structure.
[3]
(b) An array called
showroom stores 50 Car records.
Write a line of code to update the
Price of the car at index 5 to
12500.00.
[2]
3
The function
ASC() returns the ASCII value of a character.
The function
CHR() returns the character for a given ASCII value.
ASC("A") is 65
ASC("B") is 66
State the output of the following lines of code:
[3]
Turn over
4
Complete the table to show the result of each string operation on the string:
phrase = "Computer Science"
[4]
| Operation |
Result |
phrase.length |
|
phrase.substring(0, 8) |
|
phrase.left(3) |
|
phrase.upper |
|
5
The Character data type is a single unit of a Character Set.
(a) State the difference between the ASCII character set and the Unicode character set.
[2]
(b) Explain why a programmer might choose Unicode over ASCII despite Unicode using more storage space.
[2]
Section B: High-Frequency Baseline Skills
6
The following code asks a user for a number and adds 10 to it. It contains a
Runtime Error.
num = input("Enter a number: ")
total = num + 10
print(total)
(a) Identify the error in this code.
[1]
(b) Rewrite the first line to fix the error using casting.
[1]
Turn over