My readability program seems to work perfectly and since the output matches all of the outputs for the given inputs in the problem specification. However, when I submit my program, I only receive 31%.

Here is my code :

from nltk.tokenize import sent_tokenize
from cs50 import get_string

def main():
    # store text
    text = get_string("Text: ")

    # find number of words
    word_num = len(text.split())
    q = word_num / 100

    # find and calculate average number of letters per 100
    let_num = len([text[index:index+1] for index in range(len(text)) if text[index:index+1].isalpha() == True])
    let_av = let_num / q

    # find and calculate average number of sentences per 100
    sen_num = len(sent_tokenize(text))
    sen_av = sen_num / q

    index = round(0.0588 * let_av - 0.296 * sen_av - 15.8)

    if index < 1:
        print("Before Grade 1")
    elif index > 1 and index < 16:
        print(f"Grade: {index}")
        print("Grade 16+")

if __name__ == "__main__":
    main ()
  • sent_tokenize is not exactly matching the specification. I'm actually more confused by this running at all, since nltk.tokenize used to not work well with the sentimental/readability checker. text[index:index+1] for a string is same as text[index], at least for a valid index, which you should have.
    – Blauelf
    Jan 16 '20 at 14:07
  • The check50 link might have more details on which part fails. In case of the nltk issue, it would fail for not finding the input prompt (which is technically true since it would fail on the import).
    – Blauelf
    Jan 16 '20 at 14:09
  • @Blauelf in the specs they don't mention anything about not using sent_tokenize furthermore there is no check50 link :/. Thanks for the text[index] suggestion!
    – rassenguy
    Jan 16 '20 at 14:54
  • They say that any occurrence of a period, exclamation point, or question mark indicates the end of a sentence, and sent_tokenize does not always agree with that, in both directions. The result for the sample texts would probably be the same, I've just read in other places that using the nltk package causes issues on the server, crashing the script before it comes to the input prompt.
    – Blauelf
    Jan 16 '20 at 15:06
  • ooh, then I will have to implement the logic myself unless there is another package somewhere. Cheers!
    – rassenguy
    Jan 16 '20 at 15:11

Do you know the name of the package instead of using sent_tokenize? thanks

  • the package (module) im using here is called nltk --> see imports
    – rassenguy
    Feb 29 '20 at 21:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .