-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults.py
52 lines (41 loc) · 1.22 KB
/
results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
from typing import Dict
def update(totals: Dict[str, int], has_text: bool, has_audio: bool):
if has_text and has_audio:
totals["has_both"] += 1
elif has_text:
totals["has_text"] += 1
elif has_audio:
totals["has_audio"] += 1
else:
totals["has_none"] += 1
if __name__ == "__main__":
totals = {
"has_both": 0,
"has_text": 0,
"has_audio": 0,
"has_none": 0,
}
has_text = False
has_audio = False
for line in sys.stdin:
line = line.strip()
if line == "":
continue
if line.startswith("- text"):
has_text = True
continue
if line.startswith("- audio"):
has_audio = True
continue
# new book
update(totals, has_text, has_audio)
has_text = False
has_audio = False
# last book
update(totals, has_text, has_audio)
print(f"Of {sum(totals.values())} books:")
print(f" - {totals['has_text']} are available as ebooks,")
print(f" - {totals['has_audio']} are available as audiobooks,")
print(f" - {totals['has_both']} are available as both,")
print(f" - {totals['has_none']} are unavailable.")