'''
Practical No. 4: WAP in Python to read a text file and print the number of Vowels and
Consonants in the file
'''
f=open("Vowel.txt","r")
data=f.read()
V=['A','E','I','O','U','a','e','i','o','u']
C=['B','C','D','F','G','H','J','K','L','M','N','P','Q','R','S','T','V','W','X', \
'Y','Z','b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w', \
'x','y','z']
cv=0
cc=0
for i in data:
if i in V:
cv=cv+1
elif i in C:
cc=cc+1
ct=0
for i in data:
ct=ct+1
print("Number of Vowels in the file=",cv)
print("Number of Consonants in the file=",cc)
print("Number of Total Chars in the file=",ct)
f.close()
No comments:
Post a Comment