-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileCharacterCounter.py
More file actions
56 lines (39 loc) · 1.25 KB
/
FileCharacterCounter.py
File metadata and controls
56 lines (39 loc) · 1.25 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# William Starks
# 4/16/2025
# lab21.py
# NO AI
def isAlpha(data):
letterscheck = data.isalpha()
if letterscheck == True:
return True
else:
return False
def isDigit(data):
digitcheck = data.isdigit()
if digitcheck == True:
return True
else:
return False
def main():
letters = 0
digits = 0
lines = 0
try:
userfile = str(input("Enter the name of the file to open for read: "))
file = open(userfile, 'r')
line = file.readline()
while line != '':
lines += 1
for char in line:
a_check = isAlpha(char)
d_check = isDigit(char)
if a_check == True:
letters += 1
if d_check == True:
digits += 1
line = file.readline()
file.close()
print(f'The number of alphabetic letters is {letters}\nThe number of digits is {digits}\nThe number of lines is {lines}')
except FileNotFoundError:
print(f'[Errno 2] No such file or directory: {userfile}')
main()