InterviewSolution
Saved Bookmarks
| 1. |
Write a user defined function in Python that displays the number of lines starting with ‘H’ in the file Para.txt.Eg: if the file contains: Whose woods these are I think I know.His house is in the village though;He will not see me stopping hereTo watch his woods fill up with snow.Then the line count should be 2. |
|
Answer» def countH(): f = open ("Para.txt", "r") lines =0 l =f.readlines() for i in l: ifi[0]=='H': lines+=1 print "no. of lines is",lines |
|