Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

Write a method COUNTLINES() in Python to read lines from text file

‘TESTFILE.TXT’ and display the lines which are not starting with any vowel.


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




    count= 0

    f=open( 'TESTFILE.txt' , 'r' )


    for line in lines:

        if (line[ 0 ]).lower() not in 'aeiou' :

            count=count+ 1

    print( "Number of lines not starting with vowels: " ,count)


Question 27(Choice 1) -Teachoo.png



Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.