Anti_vowel code pretty much works with print but with return doesn't


My code feels so close to the desired result but maybe that’s the point is to try it with return like the instructions ask… but my code prints:

H y l k W r d s !

Is there a way to keep the basic structure of my code but use the return function. When I change print for return it returns:


def anti_vowel(text):
    for char in text:
        if char in "aeiouAEIOU":
            del char
            print char,
anti_vowel("Hey look Words!")


In order to print the result of a function that uses return. Simply print the result of calling the function…

print anti_vowel("Hey look Words!")

However, the way your code is currently structured, it will always only return one letter. This is because a function ends the moment a return key is reached. Therefore, perhaps you should try following this template:

        if INDIVDUAL_ITEM in "aeiouAEIOU":
    return PARAMETER

Make sure not to just follow the template and move on. I want to make sure that you understand how and why this works. If you have any questions, just ask.


def anti_vowel(text):
    for char in text:
        if char in "aeiouAEIOU":
            text = text.replace(char, "")
    return text

Yea that’s pretty clean and straightforward. I took out the “str” in
It is a string so I don’t need to declare str before it right?

Thanks so much though. I was close! Just had to replace last 3 lines with:

text = text.replace(char, “”)
return text

I find myself googling “difference between return and print” still. So thanks for answering that a bit. Basically return will end my function

Thanks, I am glad I was somewhat close with my logic. Sometimes I don’t know where to start with these problems


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.