Space Python Loading Python…

Returning Dictionary or List

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Parser function

Fix the codeMedium 2 stages

Move the feed parser from "Line to record" into parse_line(line), which returns the record dict, then let it return None for blank, comment and damaged lines so the loop only keeps real records.

Start the challenge

Validate a cargo record

Write the codeMedium 2 stages

Write validate_cargo(item), which returns a list of everything wrong with a cargo record: missing fields and a negative mass, then a cargo ID that doesn't match the CG- and four digits format. An empty list means the record is fine.

Start the challenge

Test the parser

Write the codeMedium 2 stages

Write assert checks for parse_line() from "Parser function": the whole record for a good line first, then None for a blank line, a comment and a line with a missing field, so a broken parser can't pass.

Start the challenge

Summary function

Write the codeMedium 2 stages

Write summarise(readings), which returns the count, min, max and mean of a list of readings as one dict, then make it handle a pass with no data and round the mean, so any program can use the summary.

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