Space Python Loading Python…

JSON-looking payload

Fix the codeMedium 2 stages

The ground station's dashboard reads status messages from Python One in JSON, the text format almost every web API uses. A JSON message is full of double quotes, and this one has an apostrophe as well:

{"status": "GO", "note": "Don't skip pre-check"}

Putting that text inside a Python string is where it goes wrong: Python takes the first inner quote as the end of the text.

Run the script: Python stops with a SyntaxError, because the double quote before status ends the text early. Fix the line so it prints exactly:

{"status": "GO", "note": "Don't skip pre-check"}

Single quotes on the outside would avoid the double quotes, but then the apostrophe in Don't ends the text. Escape the quote that clashes by putting a backslash before it: \' or \".

Get the line running
Print the payload exactly

Finish stage 1 to unlock this stage.

The message should be built from values, so the starter code uses an f-string. Run it: Python stops with a strange ValueError about a format specifier. In an f-string, every { starts a placeholder, including the one meant to open the message. Fix the line so it prints the same message:

{"status": "GO", "note": "Don't skip pre-check"}

Write each curly brace you want printed twice: {{ prints { and }} prints }.

Print the message from the values
Keep it built from the values
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

Special Characters in Print

special-characters-print.py
# Special characters in Python
# \n - new line
print("Mission log:\nDay 1: Launch\nDay 2: Orbit reached\nDay 3: Systems check")

# \t - tab (great for aligning columns)
print("\nPlanet\t\tDistance")
print("Mars\t\t225 mln km")
print("Jupiter\t\t778 mln km")
print("Saturn\t\t1,434 mln km")

# \\ - backslash (for file paths)
print("\nLog file: C:\\missions\\launch_data\\report.txt")

# \" and \' - quotes inside strings
print("Captain said: \"Initiate launch sequence!\"")
print('Engineer\'s reply: "All systems go."')
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:].