Bird
0
0

Given this simplified state machine code snippet:

medium📝 Analysis Q13 of 15
LLD - Design — Food Delivery System
Given this simplified state machine code snippet:
state = 'placed'
event = 'ship_order'
if state == 'placed' and event == 'ship_order':
    state = 'shipped'
elif state == 'shipped' and event == 'deliver_order':
    state = 'delivered'
print(state)

What will be the output if event = 'deliver_order' when state = 'placed'?
Ashipped
Bdelivered
Cplaced
Derror
Step-by-Step Solution
Solution:
  1. Step 1: Check condition for event 'deliver_order' when state is 'placed'

    The first if checks for 'ship_order' event; it does not match 'deliver_order'. The elif checks for 'shipped' state, but current state is 'placed'.
  2. Step 2: Determine state after conditions

    No condition matches, so state remains unchanged as 'placed'.
  3. Final Answer:

    placed -> Option C
  4. Quick Check:

    No matching transition keeps state same [OK]
Quick Trick: If no condition matches, state stays unchanged [OK]
Common Mistakes:
  • Assuming event triggers transition regardless of current state
  • Confusing elif with else
  • Expecting error without exception handling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes