Computer Science, asked by sidhu3417, 5 months ago

Write a function AMCount(),which should read each character of "story.txt",should count and display the occurance of alphabets A and M(including small cases a and m too​

Answers

Answered by sudhinjyothis
7

Answer:

def AMcount():

   file = open("story 1.txt", 'r')

   read = file.read()

   countA = 0

   countM = 0

   for letter in read:

       if letter in ["a", "A"]:

           countA = countA+1

       elif letter in ["m", "M"]:

           countM = countM+1

   print("A or a:", countA)

   print("M or m :", countM)

AMcount()

Explanation:

Answered by samantasatyajit503
0

Answer:

def AMCount( ):

f = open("STORY.txt", "r",)

data = f.read()

count_a = 0

count_m = 0

for i in data :

if i == "a" or i == "A":

count_a += 1

elif i == "m" or i == "M":

count_m += 1

print("A or a :", count_a )

print("M or m:", count_m)

AMCount()

Similar questions