Question 1 Write a method in Python to read lines from a text file
DIARY.TXT, and display those lines, which are starting with an alphabet ‘P’.
declaring function count( )
reading all the lines in the text file and assigning it to ‘l’
Checking if the first letter of a line is ‘P’
Closing the file
opening the text file in read mode and assigning it to file_object ‘f’
Iterating through each line in ‘l’ and assigning it to ‘line’
Prints the line which starts with ‘P’
Invoking function count( )
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.
Hi, it looks like you're using AdBlock :(
Displaying ads are our only source of revenue. To help Teachoo create more content, and view the ad-free version of Teachooo... please purchase Teachoo Black subscription.