Functions 2 and 3 of the ghost() problem
Today I’m going to explain the last two smaller functions I created. These two functions are meant to verify that there is a vowel in the first three letters submitted, and once verified will return True. First I started by creating a function only meant to check for vowels. Here is my function.
def vowel(word): vowel = 'aeiou' for v in vowel: if v in word: return True return False |
def preghost(word): if len(word) == 3: foundvowel = vowel(word) if foundvowel == False: return False else: return True else: return True |
I separated the two functions because it made it easier for me to view and understand my code. I could most certainly have combined them, and might do so in the future, but as this was my first attempt at creating a more complicated piece of code on my own I decided to simplify it as much as possible. Doing so helped me a lot in later debugging.
Notes on Debugging: The preghost() function was originally written differently. When I first wrote it I hadn’t put in my return statements in the correct spots. I had only placed them in once or twice and because of that my final processing function (ghost()), wasn’t actually running the function. As my vowel() function is only called within the preghost() function, that meant I wasn’t calling either function. When I started debugging I had no idea my bug lay in my poorly inputted return statements, that is, I didn’t have any idea until I had Robey review if for me. It was a learning experience to know that my return statements from the preghost() function, placed incorrectly, was bypassing a good chunk of my code.
Up Next Time: The final processing function to ghost()