Programmers leave TODO comments for work still to do. Searching for them is a quick way to find unfinished parts of a codebase. Print every line that contains TODO (in capitals), with its line number, then how many there were.
Input
The first line has n (1 ≤ n ≤ 200). The next n lines are the code.
Output
For each line with TODO: line N: TEXT, where TEXT is the line without spaces at the start and end. Then COUNT TODO(s).
Examples
Example 1 · Input
5
def area(r):
# TODO: check that r is not negative
return 3.14159 * r * r
print(area(2)) # TODO use math.pi
Expected output
line 2: # TODO: check that r is not negative line 5: print(area(2)) # TODO use math.pi 2 TODO(s)
Example 2 · Input
2 x = 1 print(x)
Expected output
0 TODO(s)
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Read n, then n lines with input() in a loop.
Hint 2
"TODO" in line is True when the line contains TODO anywhere.
Hint 3
Count from 1 for the line numbers; print the line with .strip().
Solution
Show one correct solution (try it yourself first)
n = int(input())
count = 0
for number in range(1, n + 1):
line = input()
if "TODO" in line:
count += 1
print(f"line {number}: {line.strip()}")
print(f"{count} TODO(s)")