Space Python Loading Python…

Signal delay

Write the codeMedium 3 stages

Flight controllers talking to ESA's Mars Express orbiter never get an instant answer. Every command travels at the speed of light, and at Mars's distance even light takes minutes.

Work out the delay for today's distance: first in seconds, then as minutes and seconds, then for the round trip. Python lets you write big numbers with underscores, like 225_000_000, so you can read them at a glance.

Work out how long a radio signal takes to reach the orbiter and print it with one decimal place:

One-way delay: 750.5 s

Time is distance divided by speed. The speed of light is already in the code as a constant, in kilometres per second.

Print the delay in seconds
Calculate from the distance

Finish stage 1 to unlock this stage.

Nobody talks about a delay of 750.5 seconds. Show it as whole minutes and seconds:

One-way delay: 12 min 31 s

Round the delay to the nearest second first, with round(), then split it with // and %, as in "Duration formatter". The order matters: round the seconds at the end instead, and a delay of 779.7 seconds turns into "12 min 60 s".

Show minutes and seconds
Round before splitting

Finish stage 2 to unlock this stage.

A command can't be confirmed until the reply comes back, so flight controllers need the round trip too. Add a second line:

One-way delay: 12 min 31 s
Round trip: 25 min 1 s

Work the round trip out from delay_s, the exact delay, not from the rounded seconds: doubling a rounded number doubles its rounding error too.

Add the round trip
Round once, at the end
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

Basic Math Operations

basic-math-operations.py
# Mission fuel calculation
fuel_total = 1000
fuel_used = 350

fuel_remaining = fuel_total - fuel_used
print("Remaining fuel:", fuel_remaining, "liters")

# Engine power output
engines = 4
power_per_engine = 250

total_power = engines * power_per_engine
print("Total power:", total_power, "kW")

# Average speed calculation
distance = 1000
time_hours = 4

speed = distance / time_hours
print("Speed:", speed, "km/h")
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:].