Skip to content

Commit

Permalink
Added error exception
Browse files Browse the repository at this point in the history
Used try, except to add error exceptions for invalid file names
  • Loading branch information
Brikaa authored Jun 22, 2018
1 parent b337c6a commit e597a5e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions CountMillionCharacters-2.0.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Get the number of each character in any given text.

"""Get the number of each character in any given text.
Inputs:
A txt file -- You will be asked for an input file. Simply input the name
of the txt file in which you have the desired text.
"""

import pprint
Expand All @@ -13,12 +12,16 @@
def main():

file_input = input('File Name: ')

with open(file_input, 'r') as info:
count = collections.Counter(info.read().upper())
try:
with open(file_input, 'r') as info:
count = collections.Counter(info.read().upper())
except FileNotFoundError:
print("Please enter a valid file name.")
main()

value = pprint.pformat(count)
print(value)
exit()


if __name__ == "__main__":
Expand Down

0 comments on commit e597a5e

Please sign in to comment.