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

EOFError

people i am getting an end of file error when i pop this code on the assisgnment platform. but this code is working pretty well on the workspace.

disemvowel.py
vowels=["a","e","i","o","u"]
def disemvowel(word):
    for letter in word:
        for vowel in vowels:
            if letter==vowel:
                newstr = word.replace(letter, "")
                word=newstr
    return word

while True:
    word=input("put any word of your choice and the vowels will be given\n >  ").lower()
    final=disemvowel(word)
    print(final)
    continue

2 Answers

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Timotheus,

There are 2 things that need fixing for this to work.

First, you'll want to get rid of that whole "while True" section that repeats the request for a string. It's not that the code is wrong, but the challenge is not expecting it so it's finding itself stuck in a loop when it thinks the program should be finished running. Taking that block out will get rid of your EOF error.

However, you'll then run into a second error, because now the upper/lowercase aspect is not covered. If you compare letter.lower() to your vowel, instead of just letter, it should be fine, like so:

vowels=["a","e","i","o","u"]
def disemvowel(word):
    for letter in word:
        for vowel in vowels:
            if letter.lower()==vowel:
                newstr = word.replace(letter, "")
                word=newstr
    return word

I hope this helps!

Thanks Louise. it worked.

but i am surprised how i have to do this: letter.lower() because i hade already lowered any input: word=input("put any word of your choice and the vowels will be given\n > ").lower()

if you note, the 'letter' variable is deriving its value from the 'word' variable and already anything that is in the 'word' is lowerd so why should i lower the 'letter'. isn't that unnecessary duplication?

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Timotheus,

Good question! The obvious problem is that it was in the section of code we took out! :-)

However, there is another problem, which is that if the user enters a string with upper case characters, like "HEY THIS string has UPPER aNd lower CaSe ChArActERs", and you store that string as all lower case (as in your original code), it will fail the challenge because you lose track of which characters were originally upper case. The challenge is expecting you to return all the consonants as they were - either upper or lower case. That's why I'm using the .lower() only for the comparison, not for actually storing the letters.

Alternatively, you could add upper case vowels to your list of vowels, and remove the .lower() in the comparison altogether.

Hopefully that clarifies things a bit!

Got you bro even more than you did. thanks a lot.