Q. Write a user-defined function in Python that displays the number of lines starting with 'H' in the file Para.
txt. Example, 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 here
To watch his woods fill up with snow.
Then the line count should be 2.
Answer =
def count (): f = open("Para.txt", "r") lines = 0 l = f.readlines () for i in l : if i[0] == 'H' : lines += 1 print("No. of lines are: ", lines) f.close()
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )