0

It showing that one test failing.

expected "Grade 8\n", not "Grade 7\n"

After I'm going to results page, copy the text they use in test and manually testing it in my console, The answer is the expected one, "Grade 8"

my code is >>>

from cs50 import get_string
import re

inString = get_string("Text: ")


#SENTENCES LIST CREATED
sentences = re.split("[?.!]", inString)
def cbk(el):
    if el == "":
        return False
    else:
        return True

sentences = list(filter(cbk, sentences))
#######################


#LETTER COUNT SECTION
numLetters = 0;
for letter in inString:
    if letter.isalpha():
        numLetters += 1
#####################

#WORDS COUNT
words = inString.split()
############

L = (numLetters / len(words)) * 100
S = (len(sentences) / len(words)) * 100

index = round(0.0588 * L - 0.296 * S - 15.8)

if index > 16:
    print("Grade 16+")
elif index < 1:
    print("Before Grade 1")
else:
    print(f"Grade {index}")
1
  • This code incorrectly returns Grade 7 for the "Alice" text. The text is one sentence. May 19 at 11:10

You must log in to answer this question.

Browse other questions tagged .