Write a function in Python to count and display the number of lines starting with alphabet A present

Опубликовано: 20 Октябрь 2024
на канале: Portal Express
1,891
44

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:

Website Link :-
https://www.pathwalla.com/2020/03/q-1...

File Handling || Q 10 || Type C || Sumita Arora || Class 12 || Computer science || Solution || IP


File Handling Playlist link ---

   • Write a program that reads a text fil...  

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


#filehandling #class12sumitaarora


computer science class 12 python,
class 12 cs sumita arora solutions,
file handling class 12 python
file handling class 12 questions