Download the text file Activity10.txt (linked here) and save it in the same directory where you save the source code for this activity. Write a Python program that reads the Activity10.txt file’s contents and determines the following:
Use the string functions isupper(), islower(), isdigit(), isspace() introduced in Section 8.3.
f=open("Activity10.txt",mode='r+',encoding='utf-8')#Open file
nmUpper=0
nmLower=0
nmDigits=0
numWhite=0
for line in f:
for ch in line:
if(ch.isdigit()):
nmDigits+=1
if ch.islower():
nmLower+=1
if ch.isupper():
nmUpper+=1
if ch.isspace():
numWhite+=1
f.close()
print("Number of uppercase letters: "+str(nmUpper))
print("Number of lowercase letters: "+str(nmLower))
print("Number of digits: "+str(nmDigits))
print("Number of whitespace characters: "+str(numWhite))
Comments
Leave a comment