I am trying to write a function named has_no_e that takes a string as an argument and returns False if the string contains the letter e and True if the string does not contains the letter e.
I have written the function using the for loop but I am failing to write a similar function that does the same thing using a while loop.
Here is my function with the for loop:
def has_no_e(word):
for letters in word:
if letters == "e":
return False
return True
And the function I have written is:
def has_no_e2(word):
index = 0
while index < len(word):
if word[index] != "e":
index += 1
return False
return True
Can you tell me what is wrong with my function with the while loop? It returns False every time not depending on whether there is "e" or not.