I have the following code which is suppose to search for the letter ‘e’ within a string, return False if ‘e’ was found within the string and return True is the ‘e’ was not found :
def has_no_e(word):
for letter in word:
if letter == 'e':
return False
return True
As per my understanding, the for loop will access the characters within wordone by one and check them against the condition i’ve set, which is if letter == 'e'
Each time i run the program, it seems the for loop is only checking the first letter for some reason!
so calling the function with has_no_e('dde','e') will result return True. but if i switch it around has_no_e('edd','e') it will return False
I’m running Python 2.7.3 on a x86 Windows 7 Ultimate machine… Thanks
is inside the body of the for loop so it will execute straight away after it checks if the first letter is
'e'(unless the first letter isethen it will returnFalse).