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 trialotarie
984 PointsWhy is my DEVOWEL program not working?
def devowel(word):
new_word = ""
for i in word:
if i == "a" or i == "e" or i == "o" or i == "u" or i == "y":
new_word == new_word
else:
new_word == new_word + "i"
return new_word
print(devowel("happy"))
print(devowel("apple"))
```
3 Answers
otarie
984 PointsSorry the formatting came out oddly.
def devowel(word):
new_word = ""
for i in word:
if i == "a" or i == "e" or i == "o" or i == "u" or i == "y":
new_word == new_word
else:
new_word == new_word + "i"
return new_word
print(devowel("happy"))
print(devowel("apple"))
Robert Richey
Courses Plus Student 16,352 PointsHi Otarie,
Logically, through each iteration of the loop, if i
is not a vowel, then add it to new_word
. Remember that ==
checks for equality and does not perform assignment.
Writing this out as pseudo-code for planning, it may look like this:
def devowel(word):
# create a variable, new_word, that will build a new string and be returned
# loop through each letter in the word
# if not a vowel
# add letter to new_word
# after finishing the loop, return new_word
Cristian Altin
12,165 Points1) When you assign a value to new_word you only use one equal like you did correctly when you defined it as an empty string. Double equals are used to compare and return True or False which you don't need with new_word
2) In your vowel list you mistakenly entered "y" instead of "i"
3) In the else statement you are adding the string "i" to new_word instead of the variable i which should contain the consonant
4) There are much better ways to write this function but you'll get better with study and practice, enjoy!