मराठी

Write a function ETCount() in Python, which should read each character of a text file “TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and T individually

Advertisements
Advertisements

प्रश्न

Write a function ETCount() in Python, which should read each character of a text file “TESTFILE.TXT” and then count and display the count of occurrence of alphabets E and T individually (including small cases e and t too).

Example:

If the file content is as follows:

Today is a pleasant day.
It might rain today.
It is mentioned on weather sites

The ETCount() function should display the output as:
E or e : 6
T or t : 9

टीपा लिहा
Advertisements

उत्तर

def ETCount() :
     file = open ('TESTFILE.TXT', 'r')
     lines = file.readlines ()
     countE=0
     countT=0
     for w in lines :
        for ch in w:
             if ch in 'Ee':
                 countE = countE + 1
              if ch in 'Tt':
                  countT=countT + 1
print ("The number of E or e : ", countE)
print ("The number of T or t : ", countT)
file.close()
shaalaa.com
Reading from a Text File in Python
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2022-2023 (March) Sample
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×