50 minutes. Self-marked against the rubric. 12 marks. In the full course this counts toward the labs and cases share (15% of the course grade). Write your answers in the boxes, then open the model answer and tick each mark you earned honestly. Nothing is sent or stored.
Scenario (invented)
A student is writing programs for a small market stall (invented). Here is Program A:
price = 12
count = 3
total = price * count
print("Total:", total)
print(total // 5)
print(total % 5)And Program B:
age = input("Your age: ")
print("Next year you will be", age + 1)Tasks
Task 1 (4 marks)
Predict the exact output of Program A.
Private: nothing you type here is sent or stored.
Task 2 (3 marks)
Program B fails when the user types 12. Name the error, the line and the cause.
Private: nothing you type here is sent or stored.
Task 3 (3 marks)
Rewrite Program B so that it prints Next year you will be 13 when the user types 12.
Private: nothing you type here is sent or stored.
Task 4 (2 marks)
Write a four-line program that stores a price and a quantity in variables and prints the total using an f-string.
Private: nothing you type here is sent or stored.
Rubric and model answer
Task 1: predict output (4 marks)
Model: three lines. Total: 36, then 7 (36 // 5), then 1 (36 % 5).
Task 2: find the fault (3 marks)
Model: a TypeError on line 2. input() returns the string "12", and Python will not add a string and the number 1.
Task 3: repair (3 marks)
Model: age = int(input("Your age: ")) then print("Next year you will be", age + 1).
Task 4: write a program (2 marks)
Model: price = 5, quantity = 4, total = price * quantity, print(f"Total: {total}"), which prints Total: 20.
Marks so far: 0 of 12