Complete the code to define the initial state as idle.
state = '[1]'
The initial state should be 'idle' to represent no movement.
Complete the code to change state to moving up when the elevator goes up.
if direction == 'up': state = '[1]'
When the elevator moves up, the state should be 'moving_up'.
Fix the error in the state transition when the elevator moves down.
if direction == 'down': state = '[1]'
The state must be 'moving_down' when the elevator moves down.
Fill both blanks to update the state correctly based on direction.
if direction == 'up': state = '[1]' elif direction == 'down': state = '[2]'
Use 'moving_up' when direction is 'up' and 'moving_down' when direction is 'down'.
Fill all three blanks to implement a function that returns the next state based on current state and direction.
def next_state(current_state, direction): if current_state == 'idle' and direction == 'up': return '[1]' elif current_state == 'idle' and direction == 'down': return '[2]' else: return '[3]'
The function returns 'moving_up' if idle and direction is up, 'moving_down' if idle and direction is down, else stays 'idle'.
