Course #8: Anti Vowel(please use single quotes!)


#1



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

The error is:

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


word = ''
def anti_vowel(text):
    for letter in text:
        if not(letter in 'aeiouAEIOU'):
            word += letter
    return word


P.S. I need SINGLE-QUOTED work. I am going to copy-and-paste the whole message, so please write down only the code(and I also need indentation).


#2

You forgot to create an empty string for 'word'. Try this:

def anti_vowel(text):
word = '' #single quotes
for letter in text:
if not (letter in 'aeiouAEIOU'):
word += letter
return word


#3

Your word = '' should be in the function, not outside. It is because it is a local variable - not a global one (hence you get an UnboundLocalError to be specific). I suggest putting it under def anti-vowel(text):.


#4

I just found another solution:
word = ''
def anti_vowel(text):
global word
for letter in text:
if not(letter in 'aeiouAEIOU'):
word += letter
return word


#5

Yes, doing that would work as well. However, you don't need the word=''for another function so it's best to keep it local. Less lines of code as well.
Good job finding out about global variables though! Have fun coding.


#6

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