HW4Q2
user_7676782
python
3 years ago
829 B
7
Indexable
def countChars(file): countDigits = 0 countLower = 0 countUpper = 0 countSpace = 0 line = file.readline() while line != '': i = 0 # check for each char if it's a digit, upper, lower or space while i < len(line): if line[i].isdigit(): countDigits += 1 if line[i].islower(): countLower += 1 if line[i].isupper(): countUpper += 1 if line[i].isspace(): countSpace += 1 i += 1 line = file.readline() print(countDigits) print(countLower) print(countUpper) print(countSpace) def main(): # txtName = input("Enter file name") fileContent = open('Q2file', 'r') countChars(fileContent) main()
Editor is loading...