Anti_vowel no mistake,but showin mistake


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#


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

But my code is working. It shows exactly what was asked for "Hy lk Wrds!" I also checked it on other python shell and it is okay there.

def anti_vowel(text):
    word = ""
    for char in text:
        if char != 'A' and char != 'a' and char != 'O' and char != 'o' and char != 'U' and char != 'u' and char != 'E' and char != 'e' and char != 'i' and char != 'I':
            word += char
    print word
print anti_vowel('"Hey look Words!"')


#2

That is because there is no return statement. Instead of print, return word.

Refactoring tip:

The if statement can be greatly reduced by using a single string and the not in operators.


#3

Instead of print word, use return word to return word to the function. Also remove the print when you call the function, the exercise doesn't require that statement.


#4

Thank you.
Works now.


#5

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