-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadability.py
More file actions
64 lines (41 loc) · 1.04 KB
/
Copy pathreadability.py
File metadata and controls
64 lines (41 loc) · 1.04 KB
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
64
import re
import math
def main():
text = input("Text: ")
# print the number of letters.
l = l_len(text)
# print the number of words.
w = w_len(text)
# print the number of sentences.
s = s_len(text)
# L = Letters ÷ Words × 100
L = (l / (w + 1) * 100)
# S = Sentences ÷ Words × 100
S = (s / (w + 1) * 100)
# coleman-liau index
index = 0.0588 * L - 0.296 * S - 15.8
if index < 1:
print("Before Grade 1")
elif index >= 16 or (round(index)) >= 16:
print("Grade 16+")
else:
print("Grade " + str(math.ceil(index)))
# print(l)
# print(w)
# print(s)
# letter count works
def l_len(l):
count = 0
for i in range(len(l)):
if str.isalpha(l[i]):
count += 1
return count
# word count works
def w_len(w):
count = len(w.split())
return count
# sentence count works
def s_len(s):
count = len(re.split(r'[.!?]+', s))
return count - 1
main()