-
Notifications
You must be signed in to change notification settings - Fork 0
/
ari1.py
47 lines (38 loc) · 1.33 KB
/
ari1.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
from sys import argv
import math
def ari(filename):
no_Of_Words = 0
no_Of_Characters = 0
no_Of_Sentences = 0
file = open(filename)
read = file.read()
file.close()
grade = {1: "Kindergarten",
2: "First Grade",
3: "Second Grade",
4: "Third Grade",
5: "Fourth Grade",
6: "Fifth Grade",
7: "Sixth Grade",
8: "Seventh Grade",
9: "Eighth Grade",
10: "Ninth Grade",
11: "Tenth Grade",
12: "Eleventh Grade",
13: "Twelfth Grade",
14: "College"
}
content = read.replace('\n', ' ')
sentences = content.split('.')
words = content.split(' ')
no_Of_Characters = len(content)
no_Of_Sentences = len(sentences) - 1
no_Of_Words = len(words)
charByWord = no_Of_Characters / no_Of_Words
wordBySent = no_Of_Words / no_Of_Sentences
score = math.ceil((4.71 * charByWord) + (0.5 * wordBySent) - 21.43)
if score > 14:
print(f"The Automated readability index for the given file, '{filename}' is {score}; its a suitable reading for Collage & adults.")
else:
print(f"The Automated readability index for the given file, '{filename}' is {score}; its a suitable reading for {grade[score]}.")
ari(sys.argv[1])