forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariation1.py
More file actions
33 lines (25 loc) · 752 Bytes
/
Copy pathvariation1.py
File metadata and controls
33 lines (25 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sys
try:
input_func = raw_input
except:
input_func = input
def count_chars(filename):
count = {}
with open(filename) as info: # inputFile Replaced with filename
readfile = info.read()
for character in readfile.upper():
count[character] = count.get(character, 0) + 1
return count
def main():
is_exist=True
#Try to open file if exist else raise exception and try again
while(is_exist):
try:
inputFile = input_func("File Name / (0)exit : ")
if inputFile == "0":
break
print(count_chars(inputFile))
except FileNotFoundError:
print("File not found...Try again!")
if __name__ == '__main__':
main()