Space Python Loading Python…

Alert banner

Write the codeMedium 3 stages

When something goes wrong on Python One, the console has to make sure nobody scrolls past it. Alerts are printed as a banner, framed by two lines of = signs:

==============================
ALERT: Cabin pressure low
==============================

The alert system sends each alert as one piece of text, so the whole banner has to come from a single f-string.

Print the alert as a three-line banner, with a border of exactly 30 = signs above and below:

==============================
ALERT: Cabin pressure low
==============================

Use one print() with one f-string. \n inside the text starts a new line, and {'=' * 30} inside the braces gives 30 equals signs, so you don't have to count them.

Print the framed alert
Send it as one piece of text

Finish stage 1 to unlock this stage.

An alert has to say where the problem is and what to do. Add two lines inside the banner, still in the same f-string:

==============================
ALERT: Cabin pressure low
Module: Habitat 2
Action: Crew to suits
==============================

Each new line inside the text needs its own \n.

Add the module and the action
Still one piece of text

Finish stage 2 to unlock this stage.

Real alert banners often carry their title in the border. Put the word with a space on each side in the middle of the top border, keeping it 30 characters wide, and drop the label from the message line:

=========== ALERT ============
Cabin pressure low
Module: Habitat 2
Action: Crew to suits
==============================

A format spec can centre text and fill the rest with a character of your choice: {' ALERT ':=^30} means "fill with =, centre, 30 wide".

Centre the title in the top border
Still one piece of text
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:].