Created
January 3, 2016 04:54
-
-
Save Krewn/36168beaa52155707d96 to your computer and use it in GitHub Desktop.
Scores a given piece of text based on the Flesch Kincaid Reading Test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def syllables(s):# int(string) | |
v = ["a","e","i","o","u","y"] | |
c = 0 | |
for k in s.lower(): | |
if(k in v and not b): | |
c+=1 | |
b = True | |
else: | |
b = False | |
return(c) | |
def fkrt(s):# float(string) # Flesch-Kincaid Reading Test | |
s.replace("\n","") | |
s.replace("\t","") | |
s = s.split(".") | |
sents = float(len(s)) | |
words = float(sum([len(k.split(" ")) for k in s])) | |
syls = float(sum([syllables(k) for k in s])) | |
return(206.835-1.015*(words/sents)-84.6*(syls/words)) | |
print(fkrt("this little pig went to market.")) # 106 | |
# 90.0–100.0 easily understood by an average 11-year-old student | |
# 60.0–70.0 easily understood by 13- to 15-year-old students | |
# 0.0–30.0 best understood by university graduates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment