-
Notifications
You must be signed in to change notification settings - Fork 12.5k
/
Copy pathcounter.py
36 lines (26 loc) · 866 Bytes
/
counter.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
"""
Class resposible for counting words for different files:
- Reduce redundant code
- Easier code management/debugging
- Code readability
"""
class Counter:
def __init__(self, text: str) -> None:
self.text = text
# Define the initial count of the lower and upper case.
self.count_lower = 0
self.count_upper = 0
self.count()
def count(self) -> None:
for char in self.text:
if char.lower():
self.count_lower += 1
elif char.upper():
self.count_upper += 1
return (self.count_lower, self.count_upper)
def get_total_lower(self) -> int:
return self.count_lower
def get_total_upper(self) -> int:
return self.count_upper
def get_total(self) -> int:
return self.count_lower + self.count_upper