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 trialjohn larson
16,594 Pointsif 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:
print(word)
for letter in word:
if letter == "a" or "e" or "i" or "o" or "u":
print(letter, end=" ")
1 Answer
Hannu Shemeikka
16,799 PointsHi,
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"
john larson
16,594 Pointsjohn larson
16,594 PointsThanks Hannu, that fixed it.