Bird
Raised Fist0

Find the bug in this refund calculation snippet:

medium📝 Analysis Q7 of Q15
LLD - Design — Hotel Booking System
Find the bug in this refund calculation snippet:
if cancellation_time < allowed_time:
refund = amount * 0.8
elif cancellation_time == allowed_time:
refund = amount * 0.5
else:
refund = 0
AThe condition should use <= for first if to include equal time
BRefund should be 100% if cancellation_time equals allowed_time
CRefund should be zero for all cases
DNo bug, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Review conditions for refund

    Usually, cancellation at allowed_time should get same refund as before or after.
  2. Step 2: Identify condition overlap

    Separate if and elif cause different refunds for equal time, which may be inconsistent.
  3. Final Answer:

    The condition should use <= for first if to include equal time -> Option A
  4. Quick Check:

    Condition fix = Use <= to cover equal time [OK]
Quick Trick: Use <= to include boundary cases [OK]
Common Mistakes:
MISTAKES
  • Splitting equal time into separate condition
  • Assuming no refund at boundary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes