Python Program to print the words starting with a vowel from a text file

302
Python Program to print the words starting with a vowel from a text file

Python program to print words that start with a vowel from the text file: In this program, we have to print all the words present in the text file that start with a vowel. So for the above problem, we first need to open the text file in a reading mode in our Python program. In my example, I am taking a text file name “content.txt” which is present in the same directory where this python file is present. So, I just typed the name of the file; otherwise, you must type the full path of the file to open it. This is the code to open the file in reading mode.

Also read:- Python program to Calculate The Area of Triangle

Python Program to print the words starting with a vowel Source Code

f = open("content.txt","r")
data = f.read()
for word in data.split():
    if word[0].lower() in ("a","e","i","o","u"):
        print(word)

LEAVE A REPLY

Please enter your comment!
Please enter your name here