Answer to Question #333015 in Python for Kaira

Question #333015

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:

  • The number of uppercase letters in the file
  • The number of lowercase letters in the file
  • The number of digits in the file
  • The number of whitespace characters in the file

Use the string functions isupper()islower()isdigit()isspace() introduced in Section 8.3.





1
Expert's answer
2022-04-24T17:16:42-0400


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))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS