Many projects have rules for the first line of a commit message. Check each message against these rules, in this order, after removing spaces at both ends, and report the first rule it breaks:
- It must not be empty:
empty. - It must be at most 50 characters:
too long. - It must start with a capital letter:
start with a capital letter. - It must not end with a period:
no period at the end.
If it breaks none, it is ok.
Input
The first line has n (1 ≤ n ≤ 100). Each of the next n lines is a commit message.
Output
For each message: N: RESULT, numbering from 1.
Examples
Example 1 · Input
4 Fix integer division in average update Add tests for the empty list. Rewrite the whole parser so that it can read every file format we support
Expected output
1: ok 2: start with a capital letter 3: no period at the end 4: too long
Example 2 · Input
2 Add a README
Expected output
1: ok 2: empty
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Remove spaces at both ends with .strip() first.
Hint 2
Do the checks in the order given and stop at the first one that fails.
Hint 3
s[0].isupper() is True for a capital letter; s.endswith(".") checks the last character.
Solution
Show one correct solution (try it yourself first)
n = int(input())
for number in range(1, n + 1):
message = input().strip()
if not message:
result = "empty"
elif len(message) > 50:
result = "too long"
elif not message[0].isupper():
result = "start with a capital letter"
elif message.endswith("."):
result = "no period at the end"
else:
result = "ok"
print(f"{number}: {result}")