Home » Python program to read a text file and display the count of vowels and consonants in the file

Python program to read a text file and display the count of vowels and consonants in the file

myfile=open(r"d:\temp\diary.txt","r")
ch=" "
vcount=0
ccount=0
while ch:
    ch=myfile.read(1)
    if ch in ['a','A','e','E','i','I','o','O','u','U']:
        vcount+=1
    else:
        ccount+=1
print("Vowels in the file:",vcount)
print("Consonants in the file:",ccount)
myfile.close()