Space Python Loading Python…

Import System Modules

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Real JSON

Write the codeEasy 2 stages

The launch code from "API response" worked on a ready-made dict, but the API really sends JSON text. Turn it into a dict with json.loads(), see what false and null become, then handle a response cut off in transfer.

Start the challenge

JSON out

Write the codeEasy 2 stages

Turn the day's mission summary dict into JSON text with json.dumps() and indent=2, see what True, False and None become, then keep the station's Polish letters readable and sort the keys so the files compare easily.

Start the challenge

Mission elapsed time

Write the codeMedium 2 stages

Parse the launch and the latest telemetry timestamp with datetime.fromisoformat(), subtract them to get the mission elapsed time, then time events reported by ground stations in three different time zones.

Start the challenge

Live T-minus

Write the codeMedium 2 stages

Extend the formatter from "Duration formatter": work out the seconds left from the launch time and datetime.now(timezone.utc) instead of a number typed by hand, then turn it into a countdown() that counts up with T+ after launch.

Start the challenge

Log to a file

Write the codeEasy 2 stages

Write the day's mission log entries to mission.log with with open(), one per line, read the file back and print it, then add an append_entry() function that adds lines at the end without wiping what is there.

Start the challenge

Telemetry from CSV

Write the codeMedium 2 stages

Point the feed parser from "Parse the whole feed" at telemetry.csv: read it with csv.DictReader, using the header row for the field names, then find the hottest temperature reading, comparing the values as numbers.

Start the challenge

Seeded simulation

Write the codeEasy 2 stages

Simulate 100 sensor readings, each with a 5% chance of a glitch, and seed random with 42 so the count is the same on every run and a test can check it exactly, then pick a kind for each glitch with random.choice().

Start the challenge

Statistics module

Fix the codeEasy 2 stages

Refactor the temperature summary: delete the hand-written mean() and median() and use statistics.mean() and statistics.median() instead, then add the standard deviation and handle passes with too few readings.

Start the challenge

Counter

Fix the codeEasy 2 stages

Refactor the level counter from "Entries per level": replace the dict and counts.get() with collections.Counter, which starts every key at 0, then list the levels from most to least common with most_common().

Start the challenge

Logging instead of print

Fix the codeMedium 2 stages

The tank check is full of prints left over from debugging. Replace them with logging calls at the right levels, so debug records stay hidden until switched on, then give the fuel code its own named logger.

Start the challenge

Telemetry pipeline

Write the codeHard 3 stages

A small but complete data pipeline: read the telemetry CSV, reject rows with unknown sensors or broken values and say why, flag readings outside each sensor's limits, and save a JSON summary for the dashboard.

Start the challenge

Launch schedule digest

Write the codeMedium 3 stages

Parse the launch schedule from JSON, keep the launches still to come, sort them by their window and print a digest line for each with the time left and any hold, then switch the digest to the live clock.

Start the challenge

Discussion

Stuck on this example or want to go further? Ask here, or see what others asked.

Log in to ask and reply.

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:].