Maintainers ask for the same facts in every bug report. Check a report for them.
What to build
A program that checks a bug report for five required fields.
Requirements
- The fields, in this order, are
Title,Steps,Expected,ActualandVersion. - A field is present if some line, after removing spaces at both ends, starts with the field name, a colon, and then some text that is not blank.
- Print
OK NAMEorMISSING NAMEfor each field. - Finally print
READYif nothing is missing, otherwiseNEEDS INFO (K missing).
Input
The first line has n (1 to 50). The next n lines are the report.
Output
Five field lines and the final line.
Constraints
1 ≤ n ≤ 50. Field names are case-sensitive.
Example
Input:
5
Title: average() crashes on an empty list
Steps: call average([])
Expected: 0
Actual: ZeroDivisionError
Version: mylib 2.1.0
Output:
OK Title
OK Steps
OK Expected
OK Actual
OK Version
READY
Why it works
Each field is an independent test on the lines, so the answer is five yes or no checks; requiring text after the colon catches the common case of a heading left empty.
Examples
5 Title: average() crashes on an empty list Steps: call average([]) Expected: 0 Actual: ZeroDivisionError Version: mylib 2.1.0
OK Title OK Steps OK Expected OK Actual OK Version READY
3 Title: It does not work Steps: Actual: crash
OK Title MISSING Steps MISSING Expected OK Actual MISSING Version NEEDS INFO (3 missing)
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
For each field, look for a stripped line that starts with the field name and a colon.
Hint 2
The report is missing the field if the text after the colon is empty.
Hint 3
Print the five results in the given order.
Solution
Show one correct solution (try it yourself first)
FIELDS = ["Title", "Steps", "Expected", "Actual", "Version"]
n = int(input())
lines = [input().strip() for _ in range(n)]
missing = 0
for name in FIELDS:
present = any(line.startswith(name + ":") and line[len(name) + 1:].strip() for line in lines)
if present:
print("OK", name)
else:
print("MISSING", name)
missing += 1
print("READY" if missing == 0 else f"NEEDS INFO ({missing} missing)")
▶ Open this solution in the compiler, then press Visualize to watch it run step by step