I'm having trouble getting an accurate value of the index. The output ends up being a negative number so the result always turns out as before grade one. I'm not sure where I went wrong
from cs50 import get_string
import string
s = get_string("Text: \n")
s = s.lower()
num_letters = 0
num_words = 0
num_sentences = 0
n = len(s)
for i in range(n):
if s.isalpha() == True:
num_letters += 1
if s[i] == '.' or s[i] == '!' or s[i] == '?':
num_sentences += 1
if (i == 0 and s[i] != ' ') or (i != n - 1 and s[i] == ' ' and s[i + 1] != ' '):
num_words += 1
L = (num_letters / num_words) * 100
S = (num_sentences / num_words) * 100
index = (0.0588 * L - 0.296 * S - 15.8)