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 Pop

Why 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

Sorry 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"))

Hi 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
Cristian Altin
12,165 Points

1) 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!