HOMEWORK

CREATE TEXT (string) ANALYZER:

criteria:

  1. Accepts input from user
  2. Counts total letters, numbers, spaces in a string
  3. Counts number of vowels
  4. Calculates average word length
  5. Correctly displays: total # of characters (including spaces + numbers), total vowels, average word length

    other criteria:

  6. ensure that program handles upper and lowercase spelling
  7. Test multiple inputs to ensure accuracy

    Criteria for above 90%:

  8. Add a unique program, function, or feature not specified by criterias
def analyze_text():
    input_string = input("Enter your sentence: ")
    letter_count = 0
    number_count = 0
    space_count = 0
    vowel_count = 0
    word_count = 0
    total_characters = 0
    for i in input_string:
        if i in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
            letter_count += 1
            total_characters += 1
            if i in "aAeEiIoOuU":
                vowel_count += 1
                total_characters += 1
        elif i in "1234567890":
            number_count += 1
            total_characters += 1
        elif i == " ":
            space_count += 1
            total_characters += 1
        else:
            total_characters += 1
            
    sentence_words = input_string.split()
    word_count = len(sentence_words)
    
    word_count = len(sentence_words)
    total_word_length = 0
    for word in sentence_words:
        word_length = len(word)
        total_word_length += word_length
    average_word_length = total_word_length/word_count
        
    print(f"The sentence entered was {input_string}")
    print(f"There are {letter_count} letters in the sentence.")
    print(f"There are {number_count} numbers in the sentence.")
    print(f"There are {vowel_count} vowels in the sentence.")
    print(f"There are {space_count} spaces in the sentence.")
    print(f"There are {word_count} words in the sentence.")
    print(f"There are {total_characters} characters in total in the sentence.")
    print(f"The average word length is: {average_word_length:.2f}")

analyze_text()
The sentence entered was Hello my name is Aditya and I am 15 years old!
There are 33 letters in the sentence.
There are 2 numbers in the sentence.
There are 14 vowels in the sentence.
There are 10 spaces in the sentence.
There are 11 words in the sentence.
There are 60 characters in total in the sentence.
The average word length is: 3.27