Read a text file and display the number of vowels/consonants/uppercase/lowercase, characters in the file
f=open("poem.txt","r")
vowels='aeiouAEIOU'
v=0
c=0
u=0
l=0
for i in f.read():
if i.isalpha():
if i.isupper():
u=u+1
else:
l=l+1
if i in vowels:
v=v+1
else:
c=c+1
print("Vowels=",v)
print("consonants=",c)
print("uppercase letters=",u)
print("lowercase letters=",l)
f.close()
Output:-
Vowels= 16
consonants= 24
uppercase letters= 1
lowercase letters= 39
No comments:
Post a Comment