0

I have been trying to complete readability python but on every result it is showing before Grade one

from cs50 import get_string

s = get_string("Text: ").strip()

num_letters, num_sentences, num_words = 0,0,0

for i in range(len(s)):
    if (i == 0  and s[i] != ' ') or (i != len(s) - 1 and s[i] == ' ' and s[i + 1] != ' '):
        num_words += 1
if s[i].isalpha():
    num_letters += 1
if s[i] == '.' or s[i] == '?' or s[i] == '!':
            num_sentences += 1


L = num_letters / num_words * 100

S = num_sentences / num_words * 100

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

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

1 Answer 1

0

Have you verified the counts are correct? It appears that the code isn't counting letters or sentences. That will result in a calculation of 0 every time.

Hint: python code is dependent on indentation in loops.

This is as far as I could get. The IDE is being very twitchy for me at the moment.

You must log in to answer this question.

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