from cs50 import get_string
text = get_string("Text: ")
letters = sentences = i = words = 0
length = len(text)
while i < length:
if text[i].isalpha():
letters += 1
//print(letters)
if (i == 0 and text[i] != " ") or (i != length and text[i] == " " and text[i + 1] != " "):
words += 1
//print(words)
if text[i] in ["?" , "!" , "."]:
sentences += 1
//print(sentences)
i += 1
L = (letters / words) * 100
S = (sentences / words) * 100
grade = round(0.0588 * L - 0.0296 * S - 15.8)
//print(f"0.0588 * {L} - 0.296 * {S} - 15.8")
//print(grade)
if grade < 1:
print("Before Grade 1")
elif grade >= 16:
print("Grade 16+")
else:
print(f"Grade {grade}")
I'm working on a task of readability in python, but the answer is too high. for example, for input;
Input : Congratulations! Today is your day. You're off to Great Places! You're off and away!
Output : Grade 11
it should print "Grade 3". I tried to check each line by printing one by one, and it worked fine and it calculates correctly until I checked this line below. the output gets higher than i expected. what did i do wrong?
grade = round(0.0588 * L - 0.0296 * S - 15.8)