-
Notifications
You must be signed in to change notification settings - Fork 0
/
readability.py
63 lines (41 loc) · 1.12 KB
/
readability.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
53
54
55
56
57
58
59
60
61
62
63
MAX_LENGTH = 1000
CONST1 = 0.0588
CONST2 = 0.296
CONST3 = 15.8
def count_letters(text):
letters = 0
for i in range(len(text)):
if((text[i] >= 'a' and text[i] <= 'z') or (text[i] >= 'A' and text[i] <= 'Z')):
letters += 1
return letters
def count_words(text):
words = 0
for i in range(len(text)):
if(text[i] == ' '):
words += 1
return words + 1
def count_sentences(text):
sentences = 0
for i in range(len(text)):
if(text[i] == '.' or text[i] == '?' or text[i] == '!'):
sentences += 1
return sentences
def main():
text = input("Text: ")
words = count_words(text)
sentences = count_sentences(text)
letters = count_letters(text)
L = letters / words * 100
S = sentences / words * 100
index = round(CONST1 * L - CONST2 * S - CONST3)
print(f"{letters} letter(s)")
print(f"{sentences} sentence(s)")
print(f"{words} word(s)")
if index > 16:
print("Grade 16+")
elif index < 1:
print("Before Grade 1")
else:
print(f"Grade {index}")
if __name__ == "__main__":
main()