← Back to Menus & Validation
Question 453
Door Open Or Closed
Door Open Or Closed
A door starts closed. 1) Open prints Door opened. and remembers the door is open, or Already open. when it is; 2) Close prints Door closed. or Already closed. the same way; 3) Quit prints Goodbye! and leaves the loop; anything else prints Unknown choice - try again.. The close branch is written; write the open branch so the is_open flag is only changed when the action makes sense. Input: one choice per line, ending with 3. Prompts are part of the output, so each message follows Choice: .
Expected Output:
1) Open 2) Close 3) Quit Choice: Door opened. 1) Open 2) Close 3) Quit Choice: Already open. 1) Open 2) Close 3) Quit Choice: Door closed. 1) Open 2) Close 3) Quit Choice: Goodbye!
= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Menus & Validation
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.