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 (Retired) Lists Redux Disemvoweled

Vlad Dyagilev
Vlad Dyagilev
9,625 Points

Why isn't my code working for Demvowling a word?

word = list(input("Which word/s do you want to remove the vowels from? "))
word_index = 0
try:
  for letter in word:
    if letter.index[word_index] == 'a' or 'e' or 'i' or 'o' or 'u':
      word = word.remove(letter)
      word_index += 1
    else:
      word_index += 1

except:
  print("Put in a word")

1 Answer

Steven Parker
Steven Parker
231,236 Points

Blockquoting code is essential for python, otherwise indentation errors are completely concealed. But a few things that are still noticeable:

  • letter is a single letter but you try to index it
  • you try to subscript an index property
  • you try to do multiple tests by combining just the targets with or (perhaps in would work there)
  • you use a list's elements as a loop counter while you are modifying the list itself

If you edit your post, remember to blockquote your code:

  1. skip a line
  2. enter a line with 3 accents ("backticks") and the language id
  3. then put your code
  4. end with a line having only 3 accents. Like this:

```py

(your code goes here)

```