8/15 Anti_Vowel - Working code evaluates as false


#1

https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2

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!")

#2

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

Change to return final.


#3

Aside:

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':
            final.append(i)
    return "".join(final)

print anti_vowel("Hey look Words!")

Tested in l a b, and lesson. Passes.


#4

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


#6

How exactly does this code work?


#8
[aeiouAEIOU]
 |   ||   |
Hey look Words!
| | |  | | ||||
Hy lk Wrds!