0
from cs50 import get_string, get_int
import sys

def main():
    statement = get_string("Text: ")

    count = len(statement)

    no_words = count_words(statement)
    no_letters = count_letters(statement)
    no_sentences = count_sentences(statement)

    L = (no_letter/no_words)*100
    S = (no_sentences/no_words)*100
    index = int(formula_application(L, S))

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

    if index > 16:
        print("Grade 16+")

    if index <= 0 :
        print("Before Grade 1")



def count_words(string):
    word_count = 0
    length = len(string)

    for i in range(length):
        if string[i] == " " :
            word_count+=1

    return word_count

def count_letters(string):
    length = len(string)

    letter_count = 0

    all_alphabets = ['a', 'b', 'c',  'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    all_letters = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']

    for i in range(lenght):
        if (string[i].lower() in all_alphabets) or (string[i].lower() in all_letters):
            letter_count+=1

    return letter_count

def count_sentences(string):
    length = len(string)
    sentence_count = 0
    all_characters = ['.', '!', '?']

    for i in range(length):
        if string[i] in all_characters:
            sentences_count+=0

    return sentence_count

def formula_application(l, s):
    ans = 0.0588 * l - 0.296 * s - 15.8
    return ans

if __name__ == "__main__":
    main()

You must log in to answer this question.

Browse other questions tagged .