runtime
254 / 500
question 254 Classes & Objects · easy

Allowed order status changes

An order's status may only change along certain paths: a pending order can be paid or cancelled, a paid order shipped, cancelled or refunded, a shipped order delivered or returned, and a delivered order returned. Write Order(order_id) with those rules stored once, on the class, and a method move_to(status) that enforces them and keeps a history.

Class attributeALLOWED = {"pending": ["paid", "cancelled"], "paid": ["shipped", "cancelled", "refunded"], "shipped": ["delivered", "returned"], "delivered": ["returned"]}
`Order(order_id)`attributes order_id, status (starts "pending"), history (starts ["pending"])
`move_to(status)`changes the status and appends it to history if the move is allowed; otherwise raises ValueError and changes nothing

Loading your progress…

Allowed order status changes — Python practice · Runtime