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 trialagzagi
2,399 PointsDisemvowel works on Spyder, but does not pass on Treehouse
Dear fellows,
I am working on the code challenge "Disemvowel".
I came up with the following code, which, as far as tested, is working and returning the expected results on Spyder. However it does not pass the challenge. I get the message "hmm, got back letters I wasn't expecting!"
Can anyone provide me with some insight into what I am doing wrong?
I appreciate your help very much!
def disemvowel(word):
word = word.lower()
vowels = ["a","e","i","o","u"]
new_word = ""
for i in word:
if i in vowels:
pass
else:
new_word += i
return new_word
1 Answer
leonardbode
Courses Plus Student 4,011 PointsHey Agustin,
It seems you are returning the string entirely lower-cased, because you assign word to word.lower() at the beginning.
disemvowel("Hey Agustin")
Yours returns --> "hy gstn"
Should return --> "Hy gstn"
Try this:
def disemvowel(word):
string = ""
for letter in word:
if letter.lower() not in "aeiou":
string += letter
return string
See if you can spot the difference yourself.
If you have any other questions I will update my answer, if you do not have any other questions:
Remember to upvote and to choose the best answer so that your question receives a checkmark in forums.
Kind regards,
Leo
agzagi
2,399 Pointsagzagi
2,399 PointsThat is awesome Leo, thank you very much!!!
I did not expect such a promt answer (literally less than 5 min after posting)
I appreciate it !!
William Li
Courses Plus Student 26,868 PointsWilliam Li
Courses Plus Student 26,868 PointsModerator Note: given Agustin's comment, I consider this issue has been resolved and marked Leo's answer as Best Answer.
I like this solution for the fact that it's very clean & Pythonic. Thanks, Leonard Bode for helping out in the forum, appreciate it.