Many projects add a checklist to every pull request. Read the checklist of a description.
What to build
A program that counts the ticked boxes of a pull request checklist and lists the open ones.
Requirements
- After removing spaces at the start of a line,
- [x]or- [X]followed by a space and text is a ticked task, and- [ ]followed by a space and text is an open task. Other lines are ignored. - Print
checked D of T, where D is the ticked tasks and T all tasks. - Then print
open: TEXTfor each open task in order. If there are no tasks at all, print onlyno checklist.
Input
The first line has n (1 to 50). The next n lines are the description.
Output
The count line and the open tasks, or no checklist.
Constraints
1 ≤ n ≤ 50.
Example
Input:
6
Fixes #12
- [x] Tests added
- [ ] Docs updated
- [x] Style checked
Thanks for reviewing!
- [ ] Changelog entry
Output:
checked 2 of 4
open: Docs updated
open: Changelog entry
Why it works
A checklist is just lines with a known start, so counting ticked and open lines gives the summary a reviewer wants, and printing the open ones tells the author what is left.
Examples
6 Fixes #12 - [x] Tests added - [ ] Docs updated - [x] Style checked Thanks for reviewing! - [ ] Changelog entry
checked 2 of 4 open: Docs updated open: Changelog entry
2 Small typo fix. No checklist here.
no checklist
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
A task line starts with "- [x]", "- [X]" or "- [ ]" after stripping.
Hint 2
The task text is what follows "] ", without spaces at the ends.
Hint 3
Print the count first, then the open tasks in order.
Solution
Show one correct solution (try it yourself first)
n = int(input())
done = 0
open_tasks = []
for _ in range(n):
line = input().strip()
if line.startswith(("- [x] ", "- [X] ")):
done += 1
elif line.startswith("- [ ] "):
open_tasks.append(line[6:].strip())
total = done + len(open_tasks)
if total == 0:
print("no checklist")
else:
print(f"checked {done} of {total}")
for text in open_tasks:
print("open:", text)
▶ Open this solution in the compiler, then press Visualize to watch it run step by step