Treehouse challenge

IB Year 1 HL Computer Science
Forum rules
Please be careful about sharing personal information. Never use any identifiable information.
Post Reply
User avatar
minseok123
Helper!
Posts: 9
Joined: 17 Sep 2018, 10:14

Treehouse challenge

Post by minseok123 » 16 Oct 2018, 00:01

link: https://teamtreehouse.com/library/pytho ... disemvowel

OK, I need you to finish writing a function for me. The function disemvowel takes a single word as a parameter and then returns that word at the end.

I need you to make it so, inside of the function, all of the vowels ("a", "e", "i", "o", and "u") are removed from the word. Solve this however you want, it's totally up to you!

Oh, be sure to look for both uppercase and lowercase vowels!


my code:

Code: Select all

def disemvowel(word):
	vowels = ["a", "e", "i", "o", "u"]
	for item in vowels:
		if item in word:
			remove.word(item)
	return word
NameError: name 'remove' is not defined..
Also, how would i look for uppercase and lowercase vowels? I don't know what to do
0 x

User avatar
Mr. MacKenty
Site Admin
Posts: 88
Joined: 28 Apr 2018, 17:06
Answers: 3

Re: Treehouse challenge

Post by Mr. MacKenty » 16 Oct 2018, 18:51

Hi Minseok,

A couple of issues with your code.
  • remove is a method used with a list, not with a string
  • we can grab capital letters by including them in the criteria we search for
  • with the replace method we can omit the conditional statement
Please don't just use this code; please seek to understand how it works.
Reference this: This link should help you.

Code: Select all

def disemvowel(word):
    vowels = ["a", "e", "i", "o", "u","A","E","I","O","U"]
    for items in vowels:
        word = word.replace(items,"")
    return word

print(disemvowel("aerewqwiounlkaHSUTAUTQWIKHASKCJHALHAOSIDU"))
minseok123 wrote:
16 Oct 2018, 00:01
link: https://teamtreehouse.com/library/pytho ... disemvowel

OK, I need you to finish writing a function for me. The function disemvowel takes a single word as a parameter and then returns that word at the end.

I need you to make it so, inside of the function, all of the vowels ("a", "e", "i", "o", and "u") are removed from the word. Solve this however you want, it's totally up to you!

Oh, be sure to look for both uppercase and lowercase vowels!


my code:

Code: Select all

def disemvowel(word):
	vowels = ["a", "e", "i", "o", "u"]
	for item in vowels:
		if item in word:
			remove.word(item)
	return word
NameError: name 'remove' is not defined..
Also, how would i look for uppercase and lowercase vowels? I don't know what to do
1 x

Post Reply