File tree Expand file tree Collapse file tree 1 file changed +20
-16
lines changed
CountMillionCharacters-Variations Expand file tree Collapse file tree 1 file changed +20
-16
lines changed Original file line number Diff line number Diff line change 1
1
import sys
2
2
3
+ try :
4
+ input_func = raw_input
5
+ except :
6
+ input_func = input
3
7
4
- def countchars (filename ):
8
+
9
+ def count_chars (filename ):
5
10
count = {}
6
11
7
12
with open (filename ) as info : # inputFile Replaced with filename
@@ -11,19 +16,18 @@ def countchars(filename):
11
16
12
17
return count
13
18
14
- if __name__ == '__main__' :
15
- if sys .version_info .major >= 3 : # if the interpreter version is 3.X, use 'input',
16
- input_func = input # otherwise use 'raw_input'
17
- else :
18
- input_func = raw_input
19
-
20
- is_exist = True
21
- #Try to open file if exist else raise exception and try again
22
- while (is_exist ):
23
- try :
24
- inputFile = input_func ("File Name : " )
25
- print (countchars (inputFile ))
26
- is_exist = False #Set False if File Name found
27
- except FileNotFoundError :
28
- print ("File not found...Try again!" )
19
+ def main ():
20
+ is_exist = True
21
+ #Try to open file if exist else raise exception and try again
22
+ while (is_exist ):
23
+ try :
24
+ inputFile = input_func ("File Name / (0)exit : " )
25
+ if inputFile == "0" :
26
+ break
27
+ print (count_chars (inputFile ))
28
+ except FileNotFoundError :
29
+ print ("File not found...Try again!" )
29
30
31
+
32
+ if __name__ == '__main__' :
33
+ main ()
You can’t perform that action at this time.
0 commit comments