Skip to content

Commit 3c5be22

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#513 from rajeshree561/patch-2
Python Program to count the number of words in a text file
2 parents 10670cd + b34084a commit 3c5be22

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fname = input("Enter file name: ")
2+
3+
num_words = 0
4+
5+
with open(fname, 'r') as f:
6+
for line in f:
7+
words = line.split()
8+
num_words += len(words)
9+
print("Number of words:")
10+
print(num_words)

0 commit comments

Comments
 (0)