Computer Science, asked by damihas, 29 days ago

WAP to read the content of the file and count how many times letter 'a' comes in file
class 12 python chaptet data handling ​

Answers

Answered by anindyaadhikari13
7

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Python.

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

counter=0

content=file.read()

for i in content:

   if i in 'Aa':

       counter=counter+1

print('File Content:\n\n',content)

print('\nNumber of times the letter \'a\' present:',counter)

\textsf{\large{\underline{Logic}:}}

  1. Open the file in reading mode.
  2. Initialize counter = 0.
  3. Read the content of the file.
  4. Go through the file content.
  5. If letter 'a' appears, increment the value of counter.
  6. Display the counter.

\textsf{\large{\underline{O{u}tput}:}}

The output for the given program is:

File Content:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Number of times the letter 'a' present: 29

Attachments:
Similar questions