0
0
LLDsystem_design~10 mins

Order tracking state machine in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the initial state of the order.

LLD
class OrderStateMachine:
    def __init__(self):
        self.state = "[1]"
Drag options to blanks, or click blank then click option'
ACreated
BShipped
CDelivered
DCancelled
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'Shipped' or 'Delivered' as the initial state.
2fill in blank
medium

Complete the code to add a method that changes the state to 'Shipped'.

LLD
def ship_order(self):
    if self.state == "Created":
        self.state = "[1]"
Drag options to blanks, or click blank then click option'
AReturned
BDelivered
CShipped
DCancelled
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the state directly to 'Delivered' without shipping.
3fill in blank
hard

Fix the error in the method that cancels an order only if it is not yet shipped.

LLD
def cancel_order(self):
    if self.state == "[1]":
        self.state = "Cancelled"
Drag options to blanks, or click blank then click option'
AShipped
BDelivered
CReturned
DCreated
Attempts:
3 left
💡 Hint
Common Mistakes
Allowing cancellation after the order is shipped.
4fill in blank
hard

Fill both blanks to define a method that marks the order as delivered only if it is shipped.

LLD
def deliver_order(self):
    if self.state == "[1]":
        self.state = "[2]"
Drag options to blanks, or click blank then click option'
AShipped
BCreated
CDelivered
DCancelled
Attempts:
3 left
💡 Hint
Common Mistakes
Changing state from 'Created' directly to 'Delivered'.
5fill in blank
hard

Fill both blanks to implement a method that returns True if the order is in a final state (Delivered or Cancelled).

LLD
def is_final_state(self):
    return self.state in ["[1]", "[2]"]
Drag options to blanks, or click blank then click option'
ACreated
BShipped
CDelivered
DCancelled
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'Created' or 'Shipped' as final states.