मराठी

Write a method COUNTLINES() in Python to read lines from the text file ‘TESTFILE.TXT’ and display the lines which do not start with any vowel. Example: If the file content is as follows:

Advertisements
Advertisements

प्रश्न

Write a method COUNTLINES() in Python to read lines from the text file ‘TESTFILE.TXT’ and display the lines which do not start with any vowel.

Example:

If the file content is as follows:

An apple a day keeps the doctor away.
We all pray for everyone’s safety.
A marked difference will come in our country.

The COUNTLINES() function should display the output as:

The number of lines not starting with any vowel - 1

टीपा लिहा
Advertisements

उत्तर

 

def COUNTLINES() :
    file = open ('TESTFILE.TXT', 'r')
    lines = file.readlines ()
    count=0
    for w in lines :
             if (w[0]).lower() not in 'aeoiu'
                 count = count + 1
    print ("The number of lines not starting with any vowel: ", count)
       file.close ()

COUNTLINES ()
shaalaa.com
Reading from a Text File in Python
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2022-2023 (March) Sample
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×