I'm getting "unsupported operand type(s) for *: 'float' and 'NoneType'" error for line 34: "s = (100 / words) * sentences".
Not sure what to make of this since count_sentences(text) does return a value.
Any help is greatly appreciated!
#import cs50
# Helper function to count letters only
def count_letters(text):
letters = sum(c.isalpha() for c in text)
return letters
"""Helper word and sentences counter function"""
def count_words(text):
words = sum(s.isspace() for s in text)
return words
def count_sentences(text):
counter = 0
for i in text:
if i == ('!' or '?' or '.'):
counter += 1
print (counter)
return counter
""" Readability - algorithm to assess writing level using Coleman-Liau index """
text = cs50.get_string("Text: ") # Prompt user for text
""" Use helper methods to count letters, words, and sentences """
letters = count_letters(text)
words = 1 + count_words(text)
sentences = count_sentences(text)
""" Calculate letters and sentences per a hundred words """
l = (100 / words) * letters
s = (100 / words) * sentences
""" Coleman-Liau index index = 0.0588 * L - 0.296 * S - 15.8 """
grade = 0.0588 * l - 0.296 * s - 15.8
""" Cast to integer and round to nearest """
if grade > 16:
print("Grade 16+")
elif grade < 1:
print("Before Grade 1")
else:
print(f"Grade: {int(round(grade))}")
return counter
in thecount_sentences()
function twice i.e, it should have only a single indentation (of 4 spaces/ a single tab).