Posts

Showing posts with the label Count the number of vowels in a file using Python

Count the number of vowels in a file using Python

Image
Count the number of vowels in a file using Python Problem description : The program reads a text file entered by the user and counts the number of vowels in the text file. Prerequisite :  Files concepts Procedure : Start. Read the file. Store the file in a string. initialize a count variable. Iterate through the string. check if the character is a vowel. increment the count variable. End. Input file : demofile.txt Techieebytes is a tech blog where you can find lot of programming exercises and solutions. The programming exercise can be solved in any of the programming language. In this program we are going to  count the number of vowels in a text file. Code : #Method 1 (using or operator) #open the text file in read mode f = open("demofile.txt", "r") #read the file and the contents will be stored as string in s. s = f.read() #initialize count variable count = 0 for i in s:          #if the letter is a vowel if(i=="a" or i=="e" or i=="i"