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 trial

Python Python Collections (2016, retired 2019) Lists Disemvowel

Fergus Clare
Fergus Clare
12,120 Points

Answer working in terminal with Python3 fails in Treehouse CLI

For the disemvowel question, I have the code below. When I run this on my local machine, I correctly get back the word sans any vowels. Running this through the interpreter however, I get a "Bummer! Hmm, got back letters I wasn't expecting". What am I doing wrong?

disemvowel.py
def disemvowel(word):
    word = word.lower()
    vowels = 'aeiou'
    for letter in word:
        if letter in vowels:
            word = word.replace(letter,'')
        else:
            pass
    print(word)

2 Answers

Steven Parker
Steven Parker
231,269 Points

You're very close, but I can see two issues:

  • the function should return the word, and it doesn't need to print anything
  • letters that are not removed should remain unchanged (this code makes everything lower case).

Once those are fixed, you should pass.

Fergus Clare
Fergus Clare
12,120 Points

Nailed it Steven Parker ! I deleted my alteration of word in the opening of the function and added a call to only modify for letter.lower() against vowels and also changed end of def to a return statement. That did it. Thanks man!

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You are sooooo close on this. Yes, you get back the word without any vowels, but you're changing the original capitalization of the word. If I were to send in "Treehouse is awesome", I would expect to get back "Trhs s wsm". Instead, I get back "trhs s wsm". Also, you need to return the word... not print it.

When you make it so that the original capitalization remains intact, your code will pass! :sparkles:

Fergus Clare
Fergus Clare
12,120 Points

Thanks Jennifer Nordell ! The advise provided by both you and Steven helped me solve the challenge. Such a simple tweak to get it right. Appreciate the assist!