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

Tony Martin
Tony Martin
5,570 Points

Why does this work in workspace but not for the disemvowel challenge?

This code functions perfectly when tried in the workspace (I tested with print() and a bunch of different made up words) yet it give the error "Bummer! Hmm, got some vowels back" whenever I try it during the challenge. In the workspace it removes all vowels without problems no matter what words I throw at it. Please help.

disemvowel.py
def disemvowel(word):
    word_as_list = list(word)
    while True:
        vowel_count = 0
        try: 
            word_as_list.remove('a')
        except ValueError:
            vowel_count += 1
        try: 
            word_as_list.remove('e')
        except ValueError:
            vowel_count += 1
        try: 
            word_as_list.remove('i')
        except ValueError:
            vowel_count += 1
        try: 
            word_as_list.remove('o')
        except ValueError:
            vowel_count += 1
        try: 
            word_as_list.remove('u')
        except ValueError:
            vowel_count += 1

        if vowel_count == 5:
            break
    word = ''.join(word_as_list)
    return word

4 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You both forgot uppercase vowels. You forgot them because I didn't mention them!

That's now been fixed. Thank you both!

Oh. Thank you!

Tony Martin
Tony Martin
5,570 Points

Mr. Kenneth Lovebeard himself! [insert my profile pic face here]

First off, it seems you are a little over-thinking this challenge.

All you need to do is this:

def disemvowel(word):
    result = ''
    for letter in word:
        if letter not in list('aeiou'):
            result += letter
    return result

Here's how it works:

  1. Pretend we call the function with a word.
  2. The program goes through every letter in our word, and if the letter is not any of the vowels (aeiou), then we'll add the letter to result.
  3. After the loop finishes, the result variable is complete, and you can return it.

That's all!

I hope this helps. ~Alex

Tony Martin
Tony Martin
5,570 Points

Grrrr! I hate it when I can't think of the answer myself. Especially one soooo so simple! As soon as I saw the code I started mentally kicking myself. So easy. :( That's a blow to my confidence :D

Thanks for the help. I appreciate the quick response.

HOWEVER, I first tried rebuilding your code without looking. I understood the concept and tried to recreate it myself. No dice, same error. Then I checked your code again, it was the same, just different variables. Tried again. No dice.

Then, I copied your code exactly into the challenge. Still no dice. "Bummer! Hmm, got some vowels back!"

This is my direct copy past from the challenge screen:

def disemvowel(word):
    result = ''
    for letter in word:
        if letter not in list('aeiou'):
            result += letter
    return result

EDIT: We both forgot to account for uppercase vowels

Hmmm.... I'll tag Kenneth Love

Mark Christian Roma
Mark Christian Roma
5,232 Points

Adding the uppercase vowels will solve the thing :)

def disemvowel(word):
    vowels = 'aeiouAEIOU' 
    result = ''
    for letter in word:
        if letter not in vowels:
            result += letter
    return result

This answer was already answered, but thanks for responding :)

Check Kenneth's post.

Why when I use java workspace and it does not work and I always receive these sentences?

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
    /*  Some terms:
        noun - Person, place or thing
        verb - An action
        adjective - A description used to modify or describe a noun
        Enter your amazing code here!
    */
    String name = console.readLine("Enter a name:  ");
    String adjective = console.readLine("Enter an adjective:  ");
    String noun = console.readLine("Enter a noun:  ");
    String verb = console.readLine("Enter a verb ending with -ing:  ");

    console.printf("Your Treestory:\n---------------\n");
    console.printf("%s is a %s %s.   ", name, adjective, noun);
    console.printf("They are always %s %s.  \n", adverb, verb);

}

Console: clear && javac TreeStory.java && java TreeStory

Console Answer: Picked up JAVA_TOOL_OPTIONS: -Xmx128m
Picked up _JAVA_OPTIONS: -Xmx128m TreeStory.java:21: error: reached end of file while parsing
}
^