Skip to content

Commit 47bb53b

Browse files
committed
Adding Lab9
1 parent 47797e2 commit 47bb53b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Code/renan/lab9.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
#ARI_Automated Readability Index
3+
#Open Txt File to read
4+
total_words = 0
5+
total_char = 0
6+
total_sent = 0
7+
#Importing your file(book) using file IO
8+
with open("ulysses.txt", encoding ="utf-8") as file:
9+
10+
ulysses_contents = file.read()
11+
12+
#Get Total Words and Characters...#Split tool splits words...characters...and sentences
13+
words = ulysses_contents.split()
14+
total_char = len(ulysses_contents)
15+
total_words += len(words)
16+
total_sent = len(ulysses_contents.split(".")) #len totals the items the split tool divided
17+
18+
print("Total Characters and Words and Sentences are: ", total_char, total_words, total_sent)
19+
20+
#Input numbers in formula to compute ARI
21+
ari_output = int(4.71 *(total_char/total_words) + 0.5 * (total_words/total_sent) - 21.43)
22+
23+
24+
#ARI Scale
25+
26+
ari_scale = {
27+
1: {'ages': '5-6', 'grade_level': 'Kindergarten'},
28+
2: {'ages': '6-7', 'grade_level': '1st Grade'},
29+
3: {'ages': '7-8', 'grade_level': '2nd Grade'},
30+
4: {'ages': '8-9', 'grade_level': '3rd Grade'},
31+
5: {'ages': '9-10', 'grade_level': '4th Grade'},
32+
6: {'ages': '10-11', 'grade_level': '5th Grade'},
33+
7: {'ages': '11-12', 'grade_level': '6th Grade'},
34+
8: {'ages': '12-13', 'grade_level': '7th Grade'},
35+
9: {'ages': '13-14', 'grade_level': '8th Grade'},
36+
10: {'ages': '14-15', 'grade_level': '9th Grade'},
37+
11: {'ages': '15-16', 'grade_level': '10th Grade'},
38+
12: {'ages': '16-17', 'grade_level': '11th Grade'},
39+
13: {'ages': '17-18', 'grade_level': '12th Grade'},
40+
14: {'ages': '18-22', 'grade_level': 'College'}
41+
}
42+
43+
#Created a value to correspond with the values of the ARI Output to the Key:Values with the ARI Scale
44+
grade_age_level = ari_scale[ari_output]
45+
46+
print(f"Your Automated Readability Index Score Is {ari_output} {ari_scale[ari_output]}") #f string allows you to use read the variable you already defined
47+
48+
print(f"This corresponds to {grade_age_level['grade_level']} level of difficulty")
49+
50+
print(f"This is suitable for an person who is {grade_age_level['ages']} years old")

0 commit comments

Comments
 (0)