Need help with anti_vowel


#1


Hi. I'm a bit stuck on the anti_vowel section. I'm not quite sure why my code isn't working. Could someone please help me? Thanks.



Oops, try again.
Did you create a function called anti_vowel? Your code threw a
"local variable 'no_vowels' referenced before assignment" error.


I'm not sure why this isn't working.


vowels = ['a', 'e', 'i', 'o', 'u']
no_vowels = ''

def anti_vowel(text):
    for letter in text:
        for char in vowels:
            if letter.lower() == char:
                no_vowels = no_vowels + letter
    print no_vowels


#2

The function can only see the reference object (the list) and not the variable. Define the variable in function scope.

Should your function print, or return?

Continued...

We can check individual letters against the vowel list without iterating by using the in operator.

if letter.lower() in vowels:

#3

Thank you! It worked and I get it now :slight_smile:


#4

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