Space Python Loading Python…

For Loop Basics

 
0:00 / 0:00

Challenge

Practise what this example shows with these challenges.

Check every reading

Write the codeEasy 2 stages

Extend the OK/WARN/CRITICAL check from Alert level so a for loop runs it over every temperature in a list, then count the WARN and CRITICAL readings for a summary line.

Start the challenge

Parse the whole feed

Write the codeEasy 2 stages

Go through a block of telemetry line by line with splitlines(), split each line at the commas and print the sensor and value, then unpack the four fields and show the clock time too.

Start the challenge

Filter the log

Write the codeMedium 2 stages

Go through the mission log and build a new list holding only the WARN and ERROR entries with append(), then let a minimum level decide what counts, the way logging tools filter by severity.

Start the challenge

Copy-pasted blocks

Fix the codeMedium 2 stages

Replace three copy-pasted tank-status blocks with a list of (name, level) pairs and one loop, keeping the output exactly the same, then add a fourth tank with a single list item and list the low tanks.

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