We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 26933d3 commit 3c8e48bCopy full SHA for 3c8e48b
razzl/0004/0004.py
@@ -0,0 +1,15 @@
1
+'''
2
+It can caculate the words in the text file
3
4
+
5
+import re
6
+def calculate_words(path):
7
+ f = open(path,'r')
8
+ lines = f.readlines()
9
+ count = 0
10
+ for line in lines:
11
+ count+=len(re.split('[,.! ?:]',line))#use the re module to split the txt file
12
+ return count-len(lines)#the txt file will inlcude the '\n' and '' so sub it
13
14
+words = calculate_words("C:/Users/razzl/Desktop/1.txt")#in python the '/' can be the path separator in all system
15
+print words
0 commit comments