-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-language-complexity.py
More file actions
49 lines (49 loc) · 1.6 KB
/
basic-language-complexity.py
File metadata and controls
49 lines (49 loc) · 1.6 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
from syllables import find_num_syllables #imports find_num_syllables()
paragraph=str(input("Enter a paragraph => ", ))
print(paragraph)
#creates variable paragaph, which is the paragraph
m=paragraph.split() #creates a list with every individual word in the paragraph in it
b=paragraph.split(".") #creates a list with every sentence as a value in it
k=0
hardwords=[]
sentlen=[]
while k<len(m):
z=m[k]
z=z.strip(".")
z=z.lower()
if z.count("-")>=1:
k+=1
elif find_num_syllables(z)>=3 and z.endswith("ed")== False and z.endswith("es")==False :
hardwords.append(m[k])
k+=1
elif find_num_syllables(z)<3:
k+=1
#above creates list with all hard words
print("Here are the hard words in this paragraph:\n", hardwords, sep="")
n=0
while n<(len(b)-1):
sent=b[n]
sent=sent.split()
length_sent=len(sent)
sentlen.append(length_sent)
n+=1
#above crates a list with the length of every sentence
i=0
syl=0
length_words=len(m)
while i<len(m):
syl+=find_num_syllables(m[i])
i+=1
#above finds the total number of syllables in the paragraph
PHW=float((len(hardwords)/len(m)))*100
PHWpercent=str(format((PHW), '.2f'))+"%"
asl=float(sum(sentlen)/(len(b)-1))
#above creates PHW, PHWpercent, and ASL
asyl=float((syl/(len(m))))
print("Statistics: ASL:"+str(format(asl, '.2f')), "PHW:"+PHWpercent, "ASYL:"+str(format(asyl, '.2f')))
#above defines asyl and prints statistics
GFRI=(0.4*(asl+PHW))
print("Readability index (GFRI):", format(GFRI, '.2f'))
FKRI=206.835-(1.015*asl)-(86.4*asyl)
print("Readability index (FKRI):", format(FKRI, '.2f'))
#above defines and prints GFRI and FKRI