Skip to content

Commit bdf7c75

Browse files
Merge pull request geekcomputers#347 from Brikaa/master
Added error exception
2 parents 3da42a8 + e597a5e commit bdf7c75

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

CountMillionCharacters-2.0.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
"""Get the number of each character in any given text.
21

2+
"""Get the number of each character in any given text.
33
Inputs:
44
A txt file -- You will be asked for an input file. Simply input the name
55
of the txt file in which you have the desired text.
6-
76
"""
87

98
import pprint
@@ -13,12 +12,16 @@
1312
def main():
1413

1514
file_input = input('File Name: ')
16-
17-
with open(file_input, 'r') as info:
18-
count = collections.Counter(info.read().upper())
15+
try:
16+
with open(file_input, 'r') as info:
17+
count = collections.Counter(info.read().upper())
18+
except FileNotFoundError:
19+
print("Please enter a valid file name.")
20+
main()
1921

2022
value = pprint.pformat(count)
2123
print(value)
24+
exit()
2225

2326

2427
if __name__ == "__main__":

0 commit comments

Comments
 (0)