An item pool tracks a total count and how many items are currently equipped. The unequipped items are available. Calculate that count when it is read rather than maintaining a third counter that could fall out of sync.
class QuestProgress:
def __init__(self, planned, completed):
self.planned = planned
self.completed = completed
@property
def remaining(self):
return self.planned - self.completed
The getter reads two ordinary instance attributes and returns their difference. There is no self.remaining assignment in the initializer. Changing completed automatically affects the next reading because the calculation runs again.
A property does not cache its result by default. If you read it twice, the getter executes twice. That is useful here because the calculation is cheap and the source values may change between reads. Storing the result once would make sense only if you deliberately wanted a snapshot rather than a current view.
Keep one source of truth for each fact. In the quest example, planned and completed steps are stored facts; remaining steps are derived from them. Updating a derived counter separately would create opportunities for contradictory state, such as totals that no longer agree.
For the exercise, each pool's total and equipped instance attributes are the supplied stored facts. Assume they are nonnegative integers with equipped no greater than total. You do not need to reject invalid input or clamp a negative result. Those would be different contracts and could hide a mistake in the source data.
Add the available property yourself, including its decorator and getter. The probe changes equipped between reads. Leave that change in place: a correct first number alone cannot distinguish a live computation from a value copied during initialization. Submit also checks an empty pool and two separate pools to keep the calculation tied to the receiving instance.
ItemPool.available property that returns the current total minus equipped, calculating the value on every access.Edit main.py. Press Run to inspect the supplied console probe, then Submit to check your implementation. The completed probe reports 7, then 4.