OCR J277: Python Coding - Official Mark Scheme

Use this guide to award marks for the corresponding student worksheet. Accept logically equivalent code that produces the correct outcome.

Question 1: Basic Input and Arithmetic [3 marks]

Indicative Content / Guidance Marks
1 mark: Correctly taking both inputs and casting to integer.
1 mark: Correct mathematical calculation for the total cost.
1 mark: Outputting the final total.
Example Code:
adults = int(input("Adult tickets: "))
children = int(input("Child tickets: "))
total = (adults * 10) + (children * 5)
print("Total cost is £", total)
3

Question 2: Selection [4 marks]

Indicative Content / Guidance Marks
1 mark: Taking input and casting to integer.
1 mark: Correct if statement for Distinction (>= 40).
1 mark: Correct elif statements handling Merit and Pass boundaries.
1 mark: Correct catch-all else or final elif for Fail, with correct print outputs for all branches.
Example Code:
score = int(input("Enter score: "))
if score >= 40:
    print("Distinction")
elif score >= 30:
    print("Merit")
elif score >= 20:
    print("Pass")
else:
    print("Fail")
4

Question 3: Iteration and Strings [4 marks]

Indicative Content / Guidance Marks
1 mark: Initialising a counter variable to 0.
1 mark: Setting up a for loop to iterate through the string.
1 mark: Correct selection (if statement) checking for "a" and incrementing the counter.
1 mark: Outputting the final total outside of the loop.
Example Code:
word = input("Enter a word: ")
count = 0
for letter in word:
    if letter == "a":
        count = count + 1
print("Total a's:", count)
4

Question 4: Arrays (Lists) and Aggregation [5 marks]

Indicative Content / Guidance Marks
1 mark: Initialising variables for total and max temperature.
1 mark: Setting up a loop to traverse the array.
1 mark: Adding the current array item to the running total.
1 mark: Checking if the current item is greater than the stored max, and updating it if true.
1 mark: Printing both results accurately after the loop concludes.
Example Code:
temps = [12, 15, 14, 18, 11]
total = 0
max_temp = temps[0]

for t in temps:
    total = total + t
    if t > max_temp:
        max_temp = t

print("Total:", total)
print("Highest:", max_temp)
5

Question 5: Robust Validation Loop [6 marks]

Indicative Content / Guidance Marks
Marks awarded for overall logic, structure, and syntax.

1 mark: Setting up a Boolean flag OR an infinite while True: loop.
1 mark: Creating the while loop structure.
1 mark: Taking the input inside the loop.
1 mark: Using len() to check if the length of the input is exactly 4.
1 mark: Updating the flag to exit the loop (or using break) AND printing "PIN accepted".
1 mark: Printing an appropriate error message if the condition is not met.
Example Code:
valid = False
while valid == False:
    pin = input("Enter a 4-digit PIN: ")
    if len(pin) == 4:
        print("PIN accepted")
        valid = True
    else:
        print("Error: PIN must be exactly 4 characters.")
6