-
Notifications
You must be signed in to change notification settings - Fork 0
/
ari.py
48 lines (40 loc) · 1.33 KB
/
ari.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
from sys import argv
import math
filename = argv[1]
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)
# print(f"no_Of_Characters : {no_Of_Characters}\nno_Of_Sentences : {no_Of_Sentences}\nno_Of_Words : {no_Of_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)
# score = 3
# print(f"score : {score}")
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]}.")