Advertisements
Advertisements
Question
Write a function, c_words()
in Python that separately counts and displays the number of uppercase and lowercase alphabets in a text file, Words.txt
.
Code Writing
Solution
def c_words():
f=open("Words.txt")
ucl=0
lcl=0
data=f.read()
for ch in data:
if ch.isalpha() and ch.isupper():
ucl += 1
elif ch.isalpha() and ch.islower():
lc += 1
print("No. of lowercase alphabets", ':', lcl)
print("No. of uppercase alphabets", ':', ucl)
shaalaa.com
Is there an error in this question or solution?