Programming Examples

Python program to copy the all word which start with constant in another file


Write a python program to copy the words from text file Lily.txt into an empty file Rose.txt which start with a consonant.

Solution

fp=open("Lily.txt","r")
data=fp.read()
fp1=open("Rose.txt","w")
output=""
str1=data.split()
for word in str1:
    if word[0].lower() not in ['a','e','i','o','u']:
        output=output+word+" "
fp1.write(output)
print("data copied")
fp.close()
fp1.close()
▶ RUN

Output/ Explanation:

data copied

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad