Time allowed: 45 minutes
| Centre number |
| | | |
|
Candidate number |
| | | |
| First name |
|
Last name |
INSTRUCTIONS
- Use black ink.
- Answer all the questions.
- Write your answers in the spaces provided.
INFORMATION
- The total mark for this paper is 40.
- The marks for each question are shown in brackets [ ].
Turn over
Section A: Prediction & Syntax
1
Look at the following code snippet written in Python.
a = "50"
b = "2"
c = a + b
print(c)
(a) State the output of the program.
[1]
(b) Explain why the program produces this output instead of calculating 52.
[1]
2
Determine the value of
result in each of the following assignment statements.
(Assume standard integer arithmetic).
[3]
| Code Statement |
Value of result |
result = 17 MOD 3 |
|
result = 17 DIV 3 (or 17 // 3) |
|
result = 2 ^ 3 (or 2 ** 3) |
|
3
A programmer is writing code to calculate the area of a rectangle.
Complete the code by filling in the missing functions and keywords.
[3]
_____________ WIDTH = 10 # This value should not change
length = ____________(input("Enter the length: "))
area = length * WIDTH
print("The area is: " + ____________(area))
4
(a) Define the term
'Variable'.
[2]
(b) Explain
one reason why a programmer would use a Constant instead of a variable for a value like VAT (20%).
[2]
Turn over
Section B: Debugging & Scope
5
The following program is designed to take a user's name and age, then print them.
There are
three errors in the code (Syntax or Logic).
Identify the
line number of each error and write the
correction.
01 name = input("Enter name")
02 age = input("Enter age")
03 nextYear = age + 1
04 Print("Next year you will be " + nextYear)
[3]
| Error Location |
Correction |
| Line ____ |
|
| Line ____ |
|
| Line ____ |
|
6
Consider the following pseudo-code:
GLOBAL score = 0
function updateScore(points)
currentLevel = 1
score = score + points
return score
endfunction
print(currentLevel)
(a) The final line
print(currentLevel) will cause an error.
Using the correct terminology, explain why this error occurs.
[2]
(b) The variable
score is a Global variable. Explain
one disadvantage of using global variables in a large program.
[2]
Turn over
Section C: Trace Tables & Records
7
Trace the execution of the following algorithm.
Note: len(word) returns the number of characters in the string.
word = "CODE"
count = 0
x = len(word)
WHILE x > 1
x = x - 1
count = count + x
print(x)
ENDWHILE
print(count)
[Image of trace table variable updates]
[5]
| word |
count |
x |
Output |
| "CODE" |
0 |
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8
The J277 specification requires knowledge of
Records.
A game stores data about a Player including their Nickname (String), Score (Integer), and IsActive (Boolean).
(a) Write the code (or pseudocode) to define this Record structure.
[3]
(b) Assume a record called
player1 has been created. Write a line of code to update the Score of
player1 to 500.
[1]
Turn over
Section D: Refinement & Mastery
9
A student has written the following code to assign a grade based on a score.
It works, but it is inefficient and hard to read.
score = int(input("Enter score"))
if score > 80:
print("Distinction")
if score > 60 and score <= 80:
print("Merit")
if score <= 60:
print("Pass")
(a) Rewrite the code using nested selection (
elif /
else) to make it more efficient.
[3]
(b) Explain why your version is more efficient for the computer processor.
[2]
10
Write a
complete program that acts as a simple Currency Converter.
The program must:
- Define a Constant for the Exchange Rate (e.g., 1.25).
- Ask the user to input the amount of GBP (£) they have.
- Validate that the amount is greater than 0.
- If it is 0 or less, output "Invalid amount".
- If it is valid, calculate the USD ($) value and output it.
- Ensure the input is cast correctly to allow for decimal numbers (e.g., £10.50).
[6]
END OF QUESTION PAPER