90 min read
Programming Practice Exam: Answer Sheet
Model answers, working and marking points for the Programming Practice Exam.
How to Use This Answer Sheet
Try the practice paper first, then compare. For calculations, check each step, not just the final answer. For written answers, the model answers show the points a marker looks for — your wording can be different, and other sensible choices with good reasons also earn marks.
Section I — Answers
| Multiple-choice answers | ||
|---|---|---|
Question 1 — Sequence
Question 1(a) — model flowchart
Read this flowchart as text
- Terminator: Start (then → INPUT student_id)
- Input/output: INPUT student_id (then → INPUT name)
- Input/output: INPUT name (then → INPUT fee)
- Input/output: INPUT fee (then → discount = fee × 0.15)
- Process: discount = fee × 0.15 (then → amount = fee − discount)
- Process: amount = fee − discount (then → OUTPUT discount, amount)
- Input/output: OUTPUT discount, amount (then → Stop)
- Terminator: Stop
Question 1(b) — model codePython
# fees.py - class fee with a 15% sibling discountstudent_id = input("Student ID: ")name = input("Name: ")fee = float(input("Monthly fee (LKR): ")) discount = fee * 0.15amount = fee - discount print(f"Student: {student_id} {name}")print(f"Discount: LKR {discount:,.2f}")print(f"Amount to pay: LKR {amount:,.2f}")Expected output
Student ID: S1024 Name: Nimali Fernando Monthly fee (LKR): 4500 Student: S1024 Nimali Fernando Discount: LKR 675.00 Amount to pay: LKR 3,825.00
Marking points: inputs in parallelograms; the two calculations in rectangles, in the right order; output of both values; float() for the fee; clear prompts and formatted output. Using a constant such as DISCOUNT_RATE = 0.15 is good practice.
Question 2 — Nested Selection
Question 2(a) — model flowchart
Read this flowchart as text
- Terminator: Start (then → INPUT service, quantity)
- Input/output: INPUT service, quantity (then → service is 1, 2 or 3?)
- Decision: service is 1, 2 or 3? (Yes → service = 1?; No → OUTPUT "Invalid service")
- Input/output: OUTPUT "Invalid service" (then → Stop)
- Decision: service = 1? (Yes → rate = 350; No → service = 2?)
- Process: rate = 350 (then → total = rate × quantity)
- Decision: service = 2? (Yes → rate = 500; No → rate = 900)
- Process: rate = 500 (then → total = rate × quantity)
- Process: rate = 900 (then → total = rate × quantity)
- Process: total = rate × quantity (then → OUTPUT total)
- Input/output: OUTPUT total (then → Stop)
- Terminator: Stop
Question 2(b) — model codePython
# laundry.py - total cost for a laundry serviceprint("1. Wash and fold (LKR 350 per kg)")print("2. Wash and iron (LKR 500 per kg)")print("3. Dry cleaning (LKR 900 per item)")service = int(input("Service type (1-3): "))quantity = int(input("Quantity (kg or items): ")) if 1 <= service <= 3: if service == 1: rate = 350 elif service == 2: rate = 500 else: rate = 900 total = rate * quantity print(f"Total cost: LKR {total:,}")else: print("Invalid service")Expected output
1. Wash and fold (LKR 350 per kg) 2. Wash and iron (LKR 500 per kg) 3. Dry cleaning (LKR 900 per item) Service type (1-3): 2 Quantity (kg or items): 4 Total cost: LKR 2,000
The nesting is the if/elif/else inside the first if. Another correct answer nests each test in the else of the one before (if service == 1: … else: if service == 2: …). Test with 1, 2 and 3, and with an invalid value such as 5 or 0.
Question 3 — A Loop
Question 3(a) — model flowchart
Read this flowchart as text
- Terminator: Start (then → n = 0)
- Process: n = 0 (then → n <= 30?)
- Decision: n <= 30? (Yes → OUTPUT n; No → Stop)
- Input/output: OUTPUT n (then → n = n + 3)
- Terminator: Stop
- Process: n = n + 3 (then → n <= 30?)
Question 3(b) — model code (while)Python
# multiples.py - multiples of 3 from 0 to 30 (while loop, matching the flowchart)n = 0while n <= 30: print(n) n = n + 3Expected output
0 3 6 9 12 15 18 21 24 27 30
Also correct — a for loopPython
for n in range(0, 31, 3): print(n)Expected output
0 3 6 9 12 15 18 21 24 27 30
Watch the end value: range(0, 30, 3) stops before 30, so 30 would be missing. The stop value must be 31 (anything above 30 and up to 33 works, but 31 is clearest). In the while loop, <= includes 30.
More lessons in Python Programming · Next: Course Exam · Previous: Programming Practice Exam
