Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Word_Count #241

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Basic-Scripts/Word_count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Author:- Prasad V Patil
# The following is a python script, which helps to count number of words, number of lines and number of characters from a file.


def count_Words(fileName):
number_of_words = 0
number_of_characters = 0
number_of_lines = 0

with open(fileName, 'r') as file:
for line in file:
wordlist = line.split()
number_of_lines += 1
number_of_words += len(wordlist)
number_of_characters += len(line)

print ("Number of Words: ", number_of_words)
print ("Number of Lines: ", number_of_lines)
print ("Number of Characters: ", number_of_characters)


#Main Program
if __name__ == '__main__':
fileName = input("Enter file name: ")
count_Words(filename)

'''
If this python file is given as file name,
i.e,
count_Words('Word_count.py')
Then, the following will be the output.
'''

#OUTPUT :-

# Number of Words: 55
# Number of Lines: 18
# Number of Characters: 548