Paper 2 Lab Skills Drills
These are original Paper 2-style practice questions. They use exact file names, function names, test calls, and expected output evidence.
These are small coding drills that practise the habits used during Paper 2: proving files, functions, routes, resources, and final checks one small step at a time.
Detailed answers are in Paper 2 Lab Skills Answers.
Revise the topic hub first:
Questions
Question 1: Folder Setup
Write required_paths() that returns this list:
["app.py", "templates/books.html", "static/style.css", "data/books.csv", "library.db"]Expected output:
['app.py', 'templates/books.html', 'static/style.css', 'data/books.csv', 'library.db'][5]
Question 2: Smoke Test
Write smoke_test() that returns "APP STARTED".
Expected output:
APP STARTED[3]
Question 3: Function Test
Write valid_category(category) that accepts only "Books" and "Stationery". Then write run_validation_tests() using assertions for "Books", "Stationery", and "Food". Return "TESTS PASSED" if all assertions pass.
Expected output:
TESTS PASSED[5]
Question 4: File Inspection
A CSV file products.csv contains:
product_id,name,price,category
P01,Pen,1.50,StationeryWrite first_csv_row(filename) that returns the first data row as a dictionary.
Expected output:
{'product_id': 'P01', 'name': 'Pen', 'price': '1.50', 'category': 'Stationery'}[5]
Question 5: JSON Inspection
A JSON file items.json contains:
[{"id": "B01", "title": "Algorithms"}, {"id": "B02", "title": "Networks"}]Write json_summary(filename) that returns (type_name, first_record), where type_name is the name of the top-level Python type.
Expected output:
('list', {'id': 'B01', 'title': 'Algorithms'})[5]
Question 6: DB Path Check
Write db_path(filename) that returns the absolute path for filename using Path(filename).resolve().
For marking, print whether db_path("library.db") ends with "library.db".
Expected output:
True[4]
Question 7: Route Check
Create a minimal Flask app with route / returning "OK". Use Flask’s test client to print the response text.
Expected output:
OK[5]
Question 8: Submission Script
Write missing_files(required) that returns required paths that do not exist.
For the test, create only:
app.py
templates/books.htmlThen test against:
["app.py", "templates/books.html", "static/style.css", "data/books.csv"]Expected output:
['static/style.css', 'data/books.csv'][6]
Question 9: Debug Print
Write debug_value(value) that returns repr(value).
Test with a form value containing spaces:
print(debug_value(" Books "))Expected output:
' Books '[3]
Question 10: Final Test Plan
Write final_dry_run_report(checks) that returns "READY" only when every check value is True; otherwise return "FIX BEFORE SUBMISSION".
Test:
print(final_dry_run_report({"starts": True, "route_ok": True, "db_ok": True}))
print(final_dry_run_report({"starts": True, "route_ok": False, "db_ok": True}))Expected output:
READY
FIX BEFORE SUBMISSION[6]
Review Checklist
After attempting these questions, check whether you can:
- make required-file checks explicit;
- create tiny runnable smoke tests before larger features;
- inspect CSV and JSON resources before full processing;
- verify Flask routes with a test client;
- convert a final dry-run checklist into clear submission evidence.