LLD - Design — Online Shopping Cart
Given the following code snippet for an order state machine, what will be the output after calling cancel() twice?
class OrderStateMachine:
def __init__(self):
self.state = 'Pending'
def cancel(self):
if self.state in ['Pending', 'Shipped']:
self.state = 'Cancelled'
else:
print('Cannot cancel from', self.state)
order = OrderStateMachine()
order.cancel()
order.cancel()
print(order.state)
