diff --git a/W/words-counter/Readme.md b/W/words-counter/Readme.md new file mode 100644 index 00000000..1abdfaf5 --- /dev/null +++ b/W/words-counter/Readme.md @@ -0,0 +1,9 @@ +## Words Counter in Python +This is a very simple program and we can easily use it and count our words + +## Note +The word_count function takes a string text as input.
+Inside the function, the split method is used to break the text into words by splitting it at whitespace (spaces, tabs, and line breaks).
+The len function is used to count the number of words in the list.
+The program then takes user input using input and calls the word_count function with the provided input.
+Finally, it prints the word count to the console. diff --git a/W/words-counter/words_counter.py b/W/words-counter/words_counter.py new file mode 100644 index 00000000..9919ea1a --- /dev/null +++ b/W/words-counter/words_counter.py @@ -0,0 +1,9 @@ +def word_count(text): + # Split the text into words using whitespace as the separator + words = text.split() + return len(words) + +if __name__ == "__main__": + input_text = input("Enter a text: ") + count = word_count(input_text) + print(f"Word count: {count}")