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
32 lines (24 loc) · 737 Bytes
/
variation1.py
File metadata and controls
32 lines (24 loc) · 737 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
try:
input = raw_input
except NameError:
pass
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("File Name / (0)exit : ").strip()
if inputFile == "0":
break
print(count_chars(inputFile))
except FileNotFoundError:
print("File not found...Try again!")
if __name__ == "__main__":
main()