Hello, this exercise has highlighted something that I haven’t exactly understood about Python programming, but up until this point I couldn’t put my finger on it… I’m having trouble grasping how python interprets indentation levels. In the following example:
def letter_check(word, letter):
_for character in word:
__if character == letter:
___return True
_return False
The code returns True if the letter is found in the word. All good so far.
If I put a single space in front of ‘return False’, the program throws an indentation error. Not sure why it has to see everything spaced twice, but not my issue here. If another space is added, yielding:
def letter_check(word, letter):
_for character in word:
__if character == letter:
___return True
__return False
the program now returns ‘False’ with the same input. With another two spaces before ‘return False’, i.e.:
def letter_check(word, letter):
_for character in word:
__if character == letter:
___return True
___return False
The program now returns ‘True’ again with the same input. I guess what I’m asking is how should my brain be interpreting the indentation levels here? I should probably straighten this out before things get much more complex…
Thanks in advance,
Joe
edit: replaced spaces with underscores to highlight issue