We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b337c6a commit e597a5eCopy full SHA for e597a5e
1 file changed
CountMillionCharacters-2.0.py
@@ -1,9 +1,8 @@
1
-"""Get the number of each character in any given text.
2
+"""Get the number of each character in any given text.
3
Inputs:
4
A txt file -- You will be asked for an input file. Simply input the name
5
of the txt file in which you have the desired text.
6
-
7
"""
8
9
import pprint
@@ -13,12 +12,16 @@
13
12
def main():
14
15
file_input = input('File Name: ')
16
17
- with open(file_input, 'r') as info:
18
- count = collections.Counter(info.read().upper())
+ try:
+ with open(file_input, 'r') as info:
+ count = collections.Counter(info.read().upper())
+ except FileNotFoundError:
19
+ print("Please enter a valid file name.")
20
+ main()
21
22
value = pprint.pformat(count)
23
print(value)
24
+ exit()
25
26
27
if __name__ == "__main__":
0 commit comments