Python Program to Count Vowels, Lines, Characters in Text File
In this article, we are going to create a python program that counts vowels, lines, and a number of characters present in a particular text file.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
- We have to open the file using open() function in python.
- Then make three variables, vowel, line and character to count the number of vowels, lines, and characters respectively.
- Make a list of vowels so that we can check whether the character is a vowel or not.
- When the count hits the ‘\n’ character we have to increase our line variable means a new line in the file.
- After that iterate over the characters of the file and count the vowels, lines, and characters.
Below is the full Implementation:
Number of vowels in MyFile.txt = 23 New Lines in MyFile.txt = 2 Number of characters in MyFile.txt = 54