Space Python Loading Python…

Live T-minus

Write the codeMedium 2 stages

The launch control screen shows T-02:15:00, and it has shown T-02:15:00 all morning. The formatter from "Duration formatter" works, but the number of seconds it formats was typed in by hand at breakfast.

Feed it the real time left, from the launch time and the clock.

Replace remaining_s = 8100 with the real time left: take now = datetime.now(timezone.utc), subtract it from launch, and turn total_seconds() into a whole number with int(). The formatter stays as it is.

When you run it, you'll see the real countdown to 5 November 2026; once that date has passed, the number turns negative until stage 2 adds T+. The check stops the clock at 12:15:00 UTC on launch day, so it expects:

T-02:15:00
Count down from the clock
The real clock

Finish stage 1 to unlock this stage.

After launch the screen should count up: T+00:05:00 five minutes in. Move the calculation into countdown(launch, now), which returns the text with T- before launch, and at launch itself, and T+ after it, then print countdown(launch, datetime.now(timezone.utc)).

With the clock stopped five minutes after launch, the check expects:

T+00:05:00

Pick the sign from whether remaining_s is negative, then format abs(remaining_s).

Count up after launch
countdown() for any moment
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

Import System Modules

import-system-modules.py
# A module is a toolbox someone else already built and tested for you

# Plain import brings in the whole module
import sys
import platform
import math

# from ... import brings in just one tool
from math import sqrt

# as gives a module a shorter nickname
import random as rng

# With a plain import: module name, a dot, then the tool
print("Python version:", platform.python_version())
print("Running on:", platform.system())
print("Python lives at:", sys.executable)

# math carries constants you would not want to type from memory
radius_km = 6371
print("Earth circumference:", round(2 * math.pi * radius_km), "km")

# sqrt arrived on its own, so it needs no dot in front
print("Square root of 9:", sqrt(9))

# rng is simply a nickname for random
print("Random sol of the Martian year:", rng.randint(1, 687))
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:].