0

Adjusted code to see how many letters, sentences and words counted. Noticed word count is lesser by one

from cs50 import get_string

text = get_string("Text: ")

letter = 0

word = 0

sentence = 0

for i in range (len(text)):
    if text[i].isalpha():
        letter += 1
    elif text[i].isspace():
        word +=1
    elif text[i] == "?" or text[i] == "!" or text[i] == ".":
        sentence += 1
    else:
        continue

L = (letter/word) * 100

S = (sentence/word) * 100

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

i = round(index)

if i > 0 and i < 17:
    print(f"Grade {i}")
elif i < 1:
    print("Before Grade 1")
else:
    print("Grade 16+")

3
  • How many words in the sentence "This is a sentence."? How many spaces? Dec 25 '20 at 20:29
  • Thanks, I've found the issue. No space after the last word. Dec 25 '20 at 20:51
  • Yea, exactly the same issue, I've fixed it though. Thank you Dec 26 '20 at 10:41
0

Found the issue, last words dont end in spaces.

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