1.

I)Write a Python program to find the number of lines in a text file„abc.txt‟.II)Write a Python program to count the word “if “ in a text fileabc.txt‟.

Answer»

(I) def COUNTLINES(): 

file=open('abc.txt','r') 

lines = file.readlines() 

count=0 

for w in lines: 

if w[0]=="A" or w[0]=="a": 

count=count+1 

print(“Total lines “,count) 

file.close()



Discussion

No Comment Found

Related InterviewSolutions