Count warnings
At the end of each orbit, the flight director reads a summary of the mission log: how many entries, and how many of them are warnings. A sudden jump in warnings is often the first sign that something is going wrong.
Count them, make sure the count can't be fooled, then summarise the log by level.
Finish stage 1 to unlock this stage.
Count the entries in the log, one per line, and the WARN entries, then print:
Entries: 6 Warnings: 3
log.count("WARN") counts how many times the text appears. A multi-line string has a new line character, "\n", between its lines, so there is one line more than there are new lines.
Finish stage 1 to unlock this stage.
A new entry has come in: INFO WARN light test complete. It's an INFO entry about the warning light, but the starter code now counts 4 warnings. Make the count match only the level, so it prints:
Entries: 7 Warnings: 3
Every level comes straight after the ] of the time and a space. Count that pattern instead of the bare word.
Finish stage 2 to unlock this stage.
The orbit summary lists every level. Replace the warnings line with one line per level:
Entries: 7 INFO: 4 WARN: 3 ERROR: 0
Use the same pattern for each: "] INFO", "] WARN" and "] ERROR". A level that never appears counts as 0.
Hints
Methods find, count, replace and split
# Searching, counting, and splitting strings
# A snippet of mission log text
report = "Mars rover Curiosity landed. Curiosity is still active."
# .find() returns the index of the first match, or -1 if not found
position = report.find("Curiosity")
print("Curiosity first appears at index:", position)
missing = report.find("Voyager")
print("Voyager index:", missing) # -1 means not found
# .count() returns how many times a substring appears
mentions = report.count("Curiosity")
print("Curiosity mentioned:", mentions, "times")
# .replace() can clean up or swap text - here we redact a name
public_report = report.replace("Curiosity", "[REDACTED]")
print(public_report)
# .split() breaks a string into a list, using a separator
crew_data = "Mark Watney,Botanist,Ares III,Sol 18"
fields = crew_data.split(",")
print("Fields:", fields)
# We can grab individual pieces by index
print("Name:", fields[0])
print("Role:", fields[1])
# Splitting on whitespace - no argument needed
sentence = "Houston we have a problem"
words = sentence.split()
print("Words:", words)
Separate arguments with commas. They're passed on every Run as sys.argv[1:].