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 11import sys
22
3+ try :
4+ input_func = raw_input
5+ except :
6+ input_func = input
37
4- def countchars (filename ):
8+
9+ def count_chars (filename ):
510 count = {}
611
712 with open (filename ) as info : # inputFile Replaced with filename
@@ -11,19 +16,18 @@ def countchars(filename):
1116
1217 return count
1318
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!" )
2930
31+
32+ if __name__ == '__main__' :
33+ main ()
You can’t perform that action at this time.
0 commit comments