DEV Community

Cover image for Word Counter
Scott Gordon
Scott Gordon

Posted on

Word Counter

# word_counter.py
#   This program counts the number of words in a sentence entered
#   by the user.
# by: Scott Gordon

def main():

    # Print greeting message
    print("***** Welcome to Word Counter *****")

    # Input users sentence and assign it to a variable.
    text = input("Enter your sentence here: ")

    # Split the sentence and save it to a list.
    split_text = text.split()

    # Count the number of words in the list.
    word_count = 0
    for word in split_text:
        word_count += 1

    # Print word count to the screen.
    print(f"The word count for your sentence is: {word_count}")


main()
Enter fullscreen mode Exit fullscreen mode

Photo by Finn Mund on Unsplash

Top comments (1)

Collapse
 
maciejewso43998 profile image
Maciejewson Collin

An Accurate Word Counter Tool is essential for writers, students, and professionals who need precise word and character counts for their content. It helps in meeting word limits for essays, articles, or social media posts while ensuring readability and clarity. This tool eliminates manual counting errors and enhances productivity by providing instant results. Whether you're drafting a blog, writing an assignment, or optimizing content for SEO, an Accurate Word Counter Tool ensures efficiency and accuracy, making writing tasks smoother and more organized.