The README is the front page of a project. Score a README by four simple checks.
What to build
A program that checks a README for a title and three sections, and prints a score out of 4.
Requirements
title: the first line that is not blank starts with#.install,usageandlicense: some line starts with##and contains that word, ignoring capital letters.- Print
title: yesortitle: no, then the same forinstall,usageandlicense, in that order. - Finally print
score S/4.
Input
The first line has n (1 to 100). The next n lines are the README text (a line may be blank).
Output
Four result lines and the score line.
Constraints
1 ≤ n ≤ 100, each line at most 100 characters.
Example
Input:
7
# Wordfreq
Counts words.
## Installation
pip install wordfreq
## Usage
Output:
title: yes
install: yes
usage: yes
license: no
score 3/4
Why it works
Each check is a small test on the lines, so the program stays four short conditions; lower-casing a line before searching makes the section check ignore capital letters.
Examples
7 # Wordfreq Counts words. ## Installation pip install wordfreq ## Usage
title: yes install: yes usage: yes license: no score 3/4
3 Just some text ## License MIT
title: no install: no usage: no license: yes score 1/4
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Skip blank lines to find the first real line; it must start with "# ".
Hint 2
For the section checks, look at lines that start with "## " and test lower-case text with "in".
Hint 3
Print the four results in the given order, then the score.
Solution
Show one correct solution (try it yourself first)
n = int(input())
lines = [input().strip() for _ in range(n)]
non_empty = [line for line in lines if line]
results = {"title": bool(non_empty) and non_empty[0].startswith("# ")}
for word in ["install", "usage", "license"]:
results[word] = any(line.startswith("## ") and word in line.lower() for line in lines)
for key in ["title", "install", "usage", "license"]:
print(f"{key}: {'yes' if results[key] else 'no'}")
print(f"score {sum(results.values())}/4")
▶ Open this solution in the compiler, then press Visualize to watch it run step by step