Skip to content

Day 8 — Extension Round (Mid-Interview Change)

Perfect choice 👍 This is exactly how real machine-coding rounds work.
Below is Day 8 – Extension Round, designed to be applied after the candidate completes Day 8 base implementation.
This teaches:
Code reading under pressure
Safe extension
Rule addition without breaking existing logic

🟢 Day 8 — Extension Round (Mid-Interview Change)

This simulates the interviewer saying: ​“Okay, now add one more requirement.”

⏱ Extension Rules (Tell Candidate)

⏰ Time for extension: 25–30 minutes
❌ Do NOT rewrite existing logic
❌ Do NOT break existing tests
❌ Do NOT change existing method signatures
✅ You may add new methods only if explicitly allowed
✅ All old behavior must still work

🧩 Extension Requirement — Partial Payment Support

New Business Requirement

The system should now support partial payments.

🔄 What Changes Conceptually?

Before:
Order could be paid only once
Payment amount had to match total exactly
Now:
Order can receive multiple payments
Order becomes PAID only when full amount is collected
Overpayment is not allowed

🧱 Updated Order States

Order can now be:
CREATED
PARTIALLY_PAID
PAID
CANCELLED

🚫 Updated Rules (Read Carefully)

Items

Same as before
Can be added only in CREATED state

Payments

New Rules
Payment amount must be > 0
Total paid amount must never exceed order total
Multiple payments allowed until fully paid

State Transitions

Current State
Action
Result State
CREATED
partial payment
PARTIALLY_PAID
PARTIALLY_PAID
partial payment
PARTIALLY_PAID
PARTIALLY_PAID
final payment
PAID
CREATED
full payment
PAID
PAID
any payment
CANCELLED
any payment
There are no rows in this table

Cancel Rules (Updated)

Order can be cancelled only if NOT PAID
Cancel clears any partial payment
Cancelled order cannot be paid

🧱 Allowed Code Changes (VERY IMPORTANT)

You MAY:

Add private variables (e.g. self.paid_amount)
Update internal logic
Add helper methods (private only)

You may NOT:

Change method signatures
Remove existing validations
Modify OrderItem or Payment classes

🔁 Existing Method — Updated Behavior

make_payment(payment)

Now should:
Return True if:
Order status is CREATED or PARTIALLY_PAID
Payment amount > 0
Total paid + payment.amount ≤ total amount
Payment is successful
Then:
Add payment amount to paid total
Update state:
If paid < total → PARTIALLY_PAID
If paid == total → PAID
Else return False.

🧠 What Candidate Must Figure Out

Without being told explicitly, candidate must:
Track paid_amount
Compare against total
Update state correctly
Preserve all Day 8 behavior
This is where strong candidates stand out.

🧪 Extension Test File (Run After Base Tests)

📄 test_day8_extension.py

from solution import Order, OrderItem, Payment


def test_partial_payment_flow():
print("Running partial payment tests...")

order = Order("O_EXT_1")

 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.