Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialVetzi Code
Python Web Development Techdegree Student 3,014 PointsWhy does this not work?
it tried it on repl.it many times, worked just fine, but doesn't work when I check work?
new_word = []
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
def disemvowel(word):
for letter in word:
if letter not in vowels:
new_word.append(letter)
return ''.join(new_word)
1 Answer
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsThe problem is that the new_word
variable is in the global scope, so as the function is run more than once, it's altering the same variable again rather than starting from scratch. The challenge seems to be passing in multiple test cases.
Bring that variable inside the scope of the function and you should be fine.
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
def disemvowel(word):
new_word = [] # this variable is declared inside the function from scratch each time
for letter in word:
if letter not in vowels:
new_word.append(letter)
return ''.join(new_word)