0
0
LLDsystem_design~10 mins

Order 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'
ACancelled
BShipped
CCreated
DDelivered
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'Shipped' or 'Delivered' as the initial state.
Using 'Cancelled' as the starting state.
2fill in blank
medium

Complete the code to transition the order from 'Created' to the next state.

LLD
def advance_order(self):
    if self.state == "Created":
        self.state = "[1]"
Drag options to blanks, or click blank then click option'
ADelivered
BShipped
CCancelled
DReturned
Attempts:
3 left
💡 Hint
Common Mistakes
Skipping 'Shipped' and going directly to 'Delivered'.
Using 'Cancelled' as the next state after 'Created'.
3fill in blank
hard

Fix the error in the code that checks if the order can be cancelled only when it is in 'Created' state.

LLD
def cancel_order(self):
    if self.state == "[1]":
        self.state = "Cancelled"
Drag options to blanks, or click blank then click option'
ACreated
BDelivered
CShipped
DReturned
Attempts:
3 left
💡 Hint
Common Mistakes
Allowing cancellation after the order is shipped or delivered.
Using 'Shipped' or 'Delivered' as the cancellable state.
4fill in blank
hard

Fill both blanks to complete the method that returns True if the order is in a final state.

LLD
def is_final_state(self):
    return self.state == "[1]" or self.state == "[2]"
Drag options to blanks, or click blank then click option'
ACancelled
BCreated
CDelivered
DShipped
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'Created' or 'Shipped' as final states.
Missing one of the final states in the check.
5fill in blank
hard

Fill all three blanks to complete the transition method that moves the order from 'Shipped' to 'Delivered' or 'Returned'.

LLD
def update_after_shipping(self, returned):
    if self.state == "[1]":
        if returned:
            self.state = "[2]"
        else:
            self.state = "[3]"
Drag options to blanks, or click blank then click option'
ACreated
BReturned
CDelivered
DShipped
Attempts:
3 left
💡 Hint
Common Mistakes
Checking wrong initial state before update.
Swapping 'Delivered' and 'Returned' states.