Q. Write a function AMCount() in Python, which should read each character of a text file STORY.TXT, should count and display the occurrence of alphabets A and M (including small cases a and m too).
Example: If the file content is as follows:
Updated information
As simplified by official websites.
The EUCount() function should display the output as:
A or a : 4
M or m: 2
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()
Output :-
A or a : 4
M or m: 2
>>>
Thanks
ReplyDeleteWelcome : )
DeleteNice
ReplyDeleteThank You : )
Deletewe opened the file..Why we didn't closed it
ReplyDeletebcs u see some other extra file in incognito mode
Deleteits grija
ReplyDeletewhat is the out put of this code
ReplyDeleteHomework is very easy after this
ReplyDeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )