Sponsor Area

TextBook Solutions for Haryana Board - English Medium Class 12 Computer And Communication Technology Computer Science With Python Chapter 7 Data File Handling

Question 1
CBSEENCO12011548

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’.

Solution
def display():
	file=open('DIARY.TXT','r')
	line=file.readline()
	while line:
		if line[0]=='P' :
			print line
			line=file.readline()
	file.close() #IGNORE

Sponsor Area