Anti_vowel HELP!


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#


I keep getting the error message:
Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "hey" when it should return "Hy lk Wrds!".


It works but Codecademy won't accept it.


word=raw_input("Please enter your word...\n")

def anti_vowel(text):
    char = "aeiouAEIOU"
    for letter1 in text:
        for letter2 in char:
            if letter1 == letter2:
                text1=word.replace(letter1, "")
    return text1
print(anti_vowel(word))


#2

Why are you looping twice? Think about this as a real world problem and how you would solve it. You want to iterate over a sentence and if that sentence contains a vowel you want to remove that word from the sentence.

Additional note: Write in pseudo code first :slight_smile:

You are really close with your code you just need to remove the unnecessary things.


#3

Couldn't you for your first loop, do what you did? Like:

for letter1 in char:

PS. I may be wrong; I just started coding...


#4

I know this sounds like harping, but it is meant in good faith: For this exercise to be meaningful we need to stay clear of built-in functions and write an algorithm to do this task using only what we've be taught up to this point. By my recollection, str.replace() is not covered in the previous units to this one so we should not be using it.

That is not to say don't learn about it on your own, just don't use it for this exercise, as the only submission. Write it as many ways as you can, for the practice and added learning that comes with it. This can be done without extra help from Python's library.

An earlier topic on this subject arose in which I basically say the same thing, so just ignore that part. There are a couple of examples using the built-ins as well as a little discussion (one-sided, mind) on usage.

https://discuss.codecademy.com/t/anti-vowel/76390


#5

Just started coding, maybe, but your perception is closer than you think.

Using the str.replace() built-in method only requires iterating the vowel list, not the text itself. That object becomes the haystack, and str.replace() strips all the vowels (the needle) it is sent to find.

So you get a pass on your rather incomplete and vague post that would otherwise be treated as a 'post to post' and normally be removed as superfluous (not adding value or insight).


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.