Space Python Loading Python…

Validate a command

Write the codeEasy 2 stages

The sequencer on Python One takes three commands from the console: start, stop and status. Operators type them in every possible way, and sometimes type something it doesn't know at all.

Accept the three commands however they are typed, reject everything else clearly, then make the error messages helpful.

Ask for a command with input(). Accept start, stop and status in any case and with spaces around them, and print what each does. For anything else, print Unknown command. For START :

Starting the sequence

Normalise the answer with strip().lower() straight away, then compare it in an if/elif chain, with else at the end.

Accept the commands
Right for every command

Finish stage 1 to unlock this stage.

Make the errors helpful. For an empty answer, ask for a command; for an unknown one, repeat what was typed, without the spaces around it but with its capitals, and list the commands that work:

Type a command: start, stop or status
Unknown command: Launch (use start, stop or status)

Keep the typed text in one variable and the lower-case version in another. Check for empty text first. For Launch, the second line is printed.

Repeat an unknown command
Handle every answer
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

If-elif-else Statement

if-elif-else-statement.py
# Oxygen level on a space station
oxygen = 19.5

if oxygen >= 23:
    status = "Warning: fire risk"
elif oxygen >= 19.5:
    status = "Normal"
elif oxygen >= 16:
    status = "Low"
else:
    status = "Critical"

print(status)

# Signal delay from a deep space probe
delay = 14.0  # minutes

if delay < 1.3:
    location = "Near the Moon"
elif delay < 5:
    location = "Inner solar system"
elif delay < 25:
    location = "Outer planets region"
else:
    location = "Deep space"

print(f"Delay: {delay} min - {location}")
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].