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 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
220,853 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)

```