──────────────────────────────────────

28. Equipment Checkout · Build an Equipment Checkout Tool

Implement a state change and explain what happens on a repeated request.

Lesson files · lessons/models-and-state/club-inventory

Before you start
- Look up an item’s record by name.
- Change one object’s state through a method.
- Use a condition to check whether a quantity is positive.

By the end
- Record equipment loans and report unknown items or exhausted stock.
- Trace the stock count across two requests for the last available item.

Where you can use it
Run an equipment desk that confirms a successful loan and warns the next person when all copies are checked out.

Give the checkout method a clear rule. A loan is possible when the available count is positive. Successful loans reduce the count by one. A request when the count is zero returns a message and leaves the count at zero. Test two requests against one remaining item.

Predict
What is the final count after two requests with one available?
- -1
- 0

Worked example (example.py)

stock = {"Tripod": 1}
if stock["Tripod"] > 0:
    stock["Tripod"] -= 1
print(stock["Tripod"])


Example result
0

Read two equipment names. Use a stock record or class for Tripod with stock 1 and Camera with stock 2. For each request print Borrowed: name after reducing stock, Unavailable: name at zero, or Unknown: name for a missing item.

Starter program (starter.py)

stock = {"Tripod": 1, "Camera": 2}
for _ in range(2):
    name = input().strip()
    print(f"Requested: {name}")


Starter input
Tripod
Tripod

Hint
Check for missing names before indexing the collection. Change stock only on the successful path.

Case 1. Try the sample
Input
Tripod
Tripod
Expected output
Borrowed: Tripod
Unavailable: Tripod

Case 2. Two successful loans
Input
Camera
Camera
Expected output
Borrowed: Camera
Borrowed: Camera

Case 3. Missing record
Input
Light
Tripod
Expected output
Unknown: Light
Borrowed: Tripod

Project checklist
Run the sample case.

Project checklist
Try one different case and explain what happened.

Marking criterion
Program behaviour (4 points)
Each required behaviour works on the supplied cases.

Marking criterion
Use of the lesson concept (3 points)
The code uses the main idea in a clear, purposeful way.

Marking criterion
Test evidence (2 points)
The reflection describes a case, its expected result and what happened.

Marking criterion
Explanation (1 points)
The learner explains a change or design decision in their own words.

Stretch
Add a return operation and a due-date report using a fixed test date.

Reflect
Which part of your program prevents the stock from becoming negative?

Check your prediction
0 The second request should leave the available count unchanged.
