Space Python Loading Python…

Methods find, count, replace and split

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Decimal comma

Fix the codeEasy 3 stages

An operator types 42,5 and float() crashes with a ValueError. Predict it, find out why, accept both commas and dots with replace(), then read pressures written like 1 013,25.

Start the challenge

Parse a telemetry line

Write the codeEasy 2 stages

Split a telemetry reading like 2026-03-14T09:30:05Z,ENG-2,412.5,C into its four fields with split(), print each with a label, then turn the value into a number and convert it to kelvin.

Start the challenge

Sensor ID parts

Write the codeMedium 2 stages

Split a sensor ID like ENG-2 into its subsystem and its unit number as an int, work out the next ID, then handle subsystems with a dash in their name using rsplit().

Start the challenge

Search the log

Write the codeMedium 2 stages

Check whether a mission log line contains ERROR with in, find where it starts with find(), including the -1 it gives when there is nothing to find, then slice out the error message.

Start the challenge

Count warnings

Write the codeMedium 3 stages

Count the entries and the WARN lines in a multi-line mission log with count(), fix the count when a message mentions WARN itself, then summarise the log by level.

Start the challenge

Command parser

Write the codeMedium 2 stages

Write parse_command(), which turns typed commands such as burn 12.5 or set mode safe into tuples and raises ValueError with a reason for anything malformed, then run a whole batch of commands and report each one.

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