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
Answer:
def
ETCount
():countE=
0
countT=
0
f=open(
'TESTFILE.txt','r'
)lines=f.readlines()
for line in lines:
for ch in line:
if ch==
'E'
or ch=='e'
:countE=countE+1
if ch==
'T'
or ch=='t'
:countT=countT+
1
print(
"Count of E/e: "
,countE)print(
"Count of T/t: ",
countT)f.close()
ETCount()