Question 6 Write a function to count the number of alphabets present in a text file “NOTES.txt”.
declaring function count_alpha( )
reading all the lines in the text file and assigning it to ‘l’
Iterating through each line in ‘l’ and assigning it to ‘line’
Iterating through each character in a word and assigning it to ‘char’
If a character is an alphabet, then increase the value of ‘c’ by 1
Invoking function count_alpha( )
Assigning a variable ‘c’ with value 0
Opening the text file in read mode and assigning it to file_object ‘f’
Iterating through each word in a line and assigning it to ‘word’
Checking if a character is an alphabet
Prints the number of alphabets
Closing the file
Output
Made by
Davneet Singh
Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo
Hi, it looks like you're using AdBlock :(
Displaying ads are our only source of revenue. To help Teachoo create more content, and view the ad-free version of Teachooo... please purchase Teachoo Black subscription.
Please login to view more pages. It's free :)
Teachoo gives you a better experience when you're logged in. Please login :)
Solve all your doubts with Teachoo Black!
Teachoo answers all your questions if you are a Black user!