Returning a different outcome outside an if/else function?

Excercise 10/12

Here I tried the following:

def letter_check(word, letter):
  for char in word:
    if char == letter:
      return True
    else:
      return False

But when the program checks against letter_check("strawberry", "a") it returns False.

APPARENTLY it wants the following code despite returning False is not inline with the if statement. Can anyone tell me why this is?

def letter_check(word, letter):
  for character in word:
    if character == letter:
      return True
  return False

That terminates the function before the loop has finished.

1 Like