Q. Write a function in Python to count and display the number of lines starting with alphabet 'A' present in a text file " LINES.TXT". e.g., the file "LINES.TXT" contains the following lines:
A boy is playing there.
There is a playground.
An aeroplane is in the sky.
Alphabets & numbers are allowed in password.
The function should display the output as 3.
You can understand by Watching video :-
Answer :-
count = 0 file = open("LINES.txt","r") lst = file.readlines() for i in lst : if i[ 0 ] == "A" : print(i) count += 1 print() print("So for number of sentences started with A : ",count) file.close()
Output :-
A boy is playing there.
An aeroplane is in the sky.
Alphabets & numbers are allowed in password.
So for number of sentences started with A : 3
>>>
write python code to display line start with g or G also display line number
ReplyDeleteIt should be in function
ReplyDeletesmartttttt
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )