File tree 1 file changed +25
-11
lines changed
1 File handle/File handle text
1 file changed +25
-11
lines changed Original file line number Diff line number Diff line change 3
3
using read function
4
4
and display those words, which are less than 4 characters. """
5
5
6
- def display_words ():
7
- with open ("story.txt" ) as F :
8
- lines = F .read ()
9
- words = lines .split ()
10
- count = 0
11
- for word in words :
12
- if (len (word ) < 4 ):
13
- print (word )
14
- count += 1
15
- return count
6
+
7
+ print ("Hey!! You can print the word which are less then 4 characters" )
8
+
9
+ def display_words (file_path ):
10
+
11
+
12
+ try :
13
+ with open (file_path , 'r' ) as F :
14
+ lines = F .read ()
15
+ words = lines .split ()
16
+ count = 0
17
+ for word in words :
18
+ if (len (word ) < 4 ):
19
+ print (word )
20
+ count += 1
21
+ return "The total number of the word's count which has less than 4 characters" , (count )
22
+
23
+ except FileNotFoundError :
24
+ print ("File not found" )
25
+
26
+ print ("Just need to pass the path of your file.." )
27
+
28
+ file_path = input ("Please, Enter file path: " )
16
29
17
30
if __name__ == "__main__" :
18
- print (display_words ())
31
+
32
+ print (display_words (file_path ))
19
33
20
34
21
35
You can’t perform that action at this time.
0 commit comments