Day 16: Word Counter In Python

Welcome to Day Sixteen of my 21-day project series! (Like seriously 16!!!)

Today I made a very very very simple Word Counter In Python.

This is not great in itself.

But, can be a good base for more complex projects.

Do read the experience

Project Contents

This mini-project is a Word Counter In Python

The Word Counter project is a simple Python program that counts the number of words in a given text.

It prompts the user to enter a text or sentence and then calculates and displays the word count.

Full Source Code

Here’s the full source code of Word Counter In Python.

def WordCounter(text:str) -> int:
    # getting sentences
    lines = text.split("\n")

    words = []
    for line in lines:
        # words from sentences
        print(line)
        for word in line.split(" "):
            words.append(word)
    return len(words)

# taking multiline input
lines = []
print("Please Enter your text: ")
while True:
    line = input()
    if not line:
        break
    lines.append(line)

# providing the string of input to the WordCounter function
words = WordCounter(str(lines))
print(f'Your text has {words} words.')

This Word Counter In Python is super easy just read and you’ll get it. Nothing else might be needed.

Yeah only if you are not a beginner.

If you are just go and get an in-depth explanation of all the topics from the website.

Possible Improvements (That I’ll add after 21 days)

So, here are the possible improvements in the Word Counter In Python:

  1. Spell Checker
  2. Word Frequency Analysis
  3. Keyword Extraction
  4. Integration with Text-to-Speech
  5. Cloud Connectivity
  6. Making a Chrome extension out of it.

And a lot more…

Experience of the day

In case you don’t know this project is a part of the brand new series that I have started. #21days21projects in python. To read more about it you can check out this page.

And for those who already know here’s my experience of the day.

Today I suddenly got to know that I have to attend a compulsory extra class.

This blew my schedule. I already have a very long schedule every day. And this was the cherry on the cake.

Because of this extra class, I got just around an hour to write the article and post for the previous day and to do the project.

That’s why this is the simplest project now on the list.

And yeah it seems unbelievable that I continued today. Cause all the challenges I faced previously while doing this challenge were somewhat known to me.

They were bound to happen at given intervals. But today, I never imagined being able to deal with something like this. That too with ease and relaxation.

Ever felt stunned by yourself?

I am glad I took up this challenge. It keeps me showing what I have never seen about me before. I might not be able to describe it here correctly.

But, I have sincerely learned a lot behind the scenes. Cause I never post the first project I started working on. It has a way of making itself a complete mess.🤷‍♀️

I seriously thought I can go no far than a 5-6 days max… (I planned to delete the posts later when I would have failed.😅)

Do let me know whether you liked this Word Counter In Python. Also, let me know if there are any suggestions.

And most importantly how was your DAY 16?

Stunned??

Well, I hope it was fun. And remember it’s perfectly awesome if you missed out. Continue to work from tomorrow.

And today just write one line of code as simple as making a variable or printing something. I made a simple project too.

Being consistent matters the most right now…

Your suggestions are welcomed!

Happy coding…

And wait, if you have some ideas for the upcoming projects do let me know that too. Even when the series ends do let me know what you like…

Leave a Reply