8 anti vowel


def anti_vowel(text):
new_word= ""
count = len(text)
text = str(text)
while count > 0:
vowels = ["a","e","i","o","u"]
for i in text:
if i == vowels:
count -= 1
return new_word

here is my code i'm not sure what i'm doing wrong can someone help me debug my code and explain what i did wrong?


Your code looks a bit off--it threw a "'str' object has no attribute 'append'" error. Check the Hint if you need help! is the error im getting


    if i in vowels:


Let's analyze this for a second. We want to be able to return a copy of a string, but that has had all the vowels stripped.

vowels = ['a','e','i','o','u']

def anti_vowel(text):
    text = str(text)                    # cast a string
    new_text = ""
    for x in text:
        if x.lower() not in vowels:
            new_text += x
    return new_text
print anti_vowel("Mississippi River")   # Msssspp Rvr


Extra Study

This goes into an area that may not yet have come up: Regular Expressions. Consider the following...

import re
def anti_vowel(text):
    nov = re.sub(r"[aeiouAEIOU]+","",text)
    return nov
print anti_vowel("Mississippi River")   # Msssspp Rvr

Don't let this distract you; just add it to your list of things to explore at the end of the track.

def anti_vowel(text):
    for char in text:
        if char not in "aeiouAEIOU":
    return "".join(string)
print anti_vowel("hey ho let's go!")


Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk rds!" when it should return "Hy lk Wrds!".

I get this in return when I used your code. Maybe I am missing something. Please check below.

vowels = ["a", "e", "i", "o", "u", "w"]

def anti_vowel(text):
    text = str(text)
    new_text = ""
    for ch in text: 
        if ch.lower() not in vowels:
            new_text += ch
    return new_text
print anti_vowel("Hey look Words!")


is not a vowel. Be sure your control data is accurate.


This worked for me without using a list. Don't know if that's a good or a bad thing!

def anti_vowel(text):
newstring = ""

for t in text:
    if t.upper() == 'A' or t.upper() == 'E' or t.upper() == 'I'or t.upper() == 'O' or t.upper() == 'U':
        newstring = newstring + ""
        newstring = newstring + t
return newstring


def anti_vowel(text):
new = ""
for i in text:
if i not in "aeiouAEIOU":
new = new + i
return new


Another, probably the worst way to do it.
I wonder, why my code is always bigger then others? Is it practice or you use some coding methodology?

def anti_vowel(text):
        while num0<=num:
            if text[num0]==vow[vowcheck0]:
            elif vowcheck0<vowcheck:
        return rework


You brought in "text" as a variable in the function then passed it to text. This to me does not make sense. Anyway, I tried a bunch of approaches and they did not work. The following code below is a much slicker way to doing it and what I finished up this exercise on.

text = str(raw_input("Please enter your text for vowel removal now: "))
def anti_vowel(text):
    vowel = ["a","e","o","i","u"]
    str_output = []
    for i in text:
        if i.lower() not in vowel:
    return "".join(str_output)
print anti_vowel(text)