Skip to content

Commit 008834a

Browse files
Merge pull request geekcomputers#322 from christianbender/changed_count_million_characters
CountMillionCharacters-Variations: added main-method and changed the program logic
2 parents 8754843 + 4c9d5e0 commit 008834a

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed
Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import 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()

0 commit comments

Comments
 (0)