195k views
2 votes
Takes a String parameter. Returns true if the String contains the letter ‘E’ (lowercase or uppercase). (Hint: use the String method indexOf). a. Create a second version that returns the number of e’s in the String.

Python, and using functions

1 Answer

4 votes

Answer:

# determine if 'e' or 'E' Is contained in string s

def contains_e(s):

return 'e' in s.lower()

# count number of e's (upper or lower case) in string s
def count_e(s):

return s.lower().count('e')

Step-by-step explanation:

There is no indexOf() method in Python. indexOf method is in Java

In Python you use the in operator to determine if a substring exists in a string. That's what I have used

User Vinod HC
by
4.9k points