Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Lists Redux Removing Items From A List

if statement failing to target only vowels. I can't see why.

My intention was to print only the vowels, but every letter is being printed not just the vowels.

word_list = ["alphacentauriano"]
vowel_list = []

for word in word_list:
    for letter in word:
        if letter == "a" or "e" or "i" or "o" or "u":
            print(letter, end=" ")

1 Answer

Hannu Shemeikka
Hannu Shemeikka
16,799 Points


The problem is that on line

if letter == "a" or "e" or "i" or "o" or "u":

you are comparing if letter equals to "a" 'or' "e" is true. You are not comparing if letter equals to e. Since the second 'or' comparison is always true, all the letters are printed.

You always need to include the variable when you are comparing it to something, e.q.

if letter == "a" or letter == "e"

Thanks Hannu, that fixed it.