Space Python Loading Python…

Text Formatting with f-strings

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Log line format

Write the codeEasy 2 stages

Turn values into a log line like [T+00:12:05] INFO Engines nominal with an f-string, then build the timestamp from numbers with zero padding.

Start the challenge

Units and separators

Write the codeEasy 3 stages

Print 7.6612 as Speed: 7.66 km/s, 1234567 as Mass: 1,234,567 kg and a fuel fraction as a percentage, using format specs in f-strings.

Start the challenge

Aligned status board

Write the codeMedium 3 stages

Print systems and their states in aligned columns with width specifiers like {name:<12}, then add a header and a right-aligned column of readings.

Start the challenge

Telemetry report

Write the codeMedium 2 stages

Extend the parser from "Parse a telemetry line" to read three readings from a multi-line feed, print each as one row, then turn them into a report with a header and aligned columns.

Start the challenge

Daily mission report

Write the codeMedium 2 stages

Turn the day's subsystem status into a fixed-width report for the shift handover, with aligned columns and a totals line, then save the same data as a CSV file with csv.DictWriter for the spreadsheet people.

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