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 trialHeidi Ulrich
4,624 PointsWhy does this code not pass?
I can't get why this does not pass. It does the trick, whether I return or print the output, it fails to pass. Why?
vowels = ['a','e','i','o','u']
uppervowels = [letter.upper() for letter in vowels]
def disemvowel(word):
consos = []
for letter in word:
if letter in vowels or letter in uppervowels:
continue
else:
consos.append(letter)
output = ''.join(consos)
return output
while True:
the_word = input('> ')
print disemvowel(the_word)
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! Your code is just fine and does, in fact, pass the challenge. But the problem here is that while you were testing it, you forgot to remove the bottom part:
If I remove this part, your code passes:
while True:
the_word = input('> ')
print disemvowel(the_word)
Remember, in these challenges if they don't ask you to call a function yourself, it's best not to do so. In fact, it's best not to do anything the challenge doesn't explicitly ask for. Even if functional, it can cause the challenge to fail.
Hope this helps!
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsYou can also simplify your code as follows:
def disemvowel(word):
output = ''
for letter in word:
if letter.lower() not in vowels:
output += letter
return output
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsI forgot to mention, vowels can be a word, does not need to be a list. For example vowels = 'aeiou' will work.
Heidi Ulrich
4,624 PointsThank you! The letter.lower() part is smart, I did not think about it that way around. It gets rid of the ugly doubling of the vowels list. And so is the mention of vowels not needing to be a list at all... Can't mark this one as best, but it sure is a good eyeopener! I'm all for simplifying code!
Heidi Ulrich
4,624 PointsHeidi Ulrich
4,624 PointsThanks! Will remember it.