8/15 Anti_Vowel - Working code evaluates as false



I got my code written and anti_vowel("Hey look Words!") yield desired result in the console as "Hy lk Wrds!" however I evaluated as false with the following message:

"Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "None" when it should return "Hy lk Wrds!"."

Would like to know if there's anything wrong with my code or this is more of a bug?

Below is my code:

        def anti_vowel(text):
            final = ""
            for i in text:
                if i not in 'aeiouAEIOU':
                    final += i
            print final
        print anti_vowel("Hey look Words!")


When we see the word returns in an error message that usually means our function should return something.

Change to return final.



Reliable advice recommends that we treat strings as immutable objects, meaning we should not be effecting changes on a string, directly, but rather create a list, make the changes, then join the elements to make a string afterward.

So your code would look like this:

def anti_vowel(text):
    final = []
    for i in text:
        if i not in 'aeiouAEIOU':
    return "".join(final)

print anti_vowel("Hey look Words!")

Tested in l a b, and lesson. Passes.


A post was split to a new topic: List indices must be integers, not str


How exactly does this code work?

 |   ||   |
Hey look Words!
| | |  | | ||||
Hy lk Wrds!