Matt Fuller7,486 Points
Python Collections (2016, retired 2019) - challenge task 1 of 1
Took quite a break from self learning coding, absolutely clueless with this one. Can anyone please explain?
def disemvowel(word): vowels = ("a", "e", "i", "o", "u") word = input("what word would you like to disemvowel?\n> ") if not vowels == 'word': exit() else: print ("Removing vowels.") word.remove(vowels)
Jeff MudayTreehouse Moderator 24,879 Points
Since this is a coding Challenge. It has an automated grader, so you are NOT supposed to user interactive input() function.
But you look like you do understand some Python concepts, so let's build on that.
There are many correct approaches to this problem. One way is to make a new_word that does not contain vowels. This is accomplished by iterating over the word letter by letter and checking if the letter is NOT a vowel.
Hint: the grader will check both upper and lower case vowels too!
def disemvowel(word): vowels = 'aeiouAEIOU' # the new_word starts as an empty string new_word = '' for letter in word: # check if the current letter is NOT a vowel, copy it into the new_word # and the vowels are skipped if not(letter in vowels): new_word += letter # finally, return the new_word return new_word