Exercise 1: Adding a "Buy One Get One Half Off" Discount to Both Versions — Possible Solution ==================================================================== ADDING IT TO THE if/elif VERSION ------------------------------ def calculate_price(price, discount_type): if discount_type == 'percentage': return price * 0.9 elif discount_type == 'flat': return price - 5 elif discount_type == 'bogo_half': return price * 0.75 else: return price This requires editing the existing function directly, adding one more elif branch alongside the existing ones. ADDING IT TO THE OBJECT-BASED VERSION ------------------------------ class BogoHalfDiscount: def apply(self, price): return price * 0.75 This requires only a new, self-contained class - calculate_price_v2 itself is not touched at all, exactly like this chapter's own LoyaltyDiscount example. VERIFYING BOTH AGREE FOR PRICE=100 ------------------------------ calculate_price(100, 'bogo_half') = 100 * 0.75 = 75.0 calculate_price_v2(100, BogoHalfDiscount()) = 75.0 Both versions return 75.0 - an exact match. WHY THIS CONFIRMS THE CHAPTER'S OWN PATTERN ------------------------------ This is the third time the exact same shape has appeared: a new discount type needs one new elif branch (touching existing code) in the first version, and one new self-contained class (touching nothing existing) in the second - precisely mirroring how LoyaltyDiscount was added in this chapter's own second demonstration. WHY THIS WORKS AS AN ANSWER ------------------------------ The answer shows the actual code change required in each version side by side, computes the result both ways rather than assuming they match, and confirms the match numerically instead of just asserting it, following the same verification discipline this chapter's own two demonstrations used.