8 anti vowel


#1

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:
del(i)
else:
new_word.append(str(i))
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?


#2

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


#3

    if i in vowels:

#4

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

#5

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.


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

#10

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!")

#11

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


#12

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 + ""
    else:
        newstring = newstring + t
return newstring

#13

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


#15

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):
        num=len(text)-1
        num0=0
        vow="aeiouAEIOU"
        vowcheck=len(vow)-1
        vowcheck0=0
        rework=""
        while num0<=num:
            if text[num0]==vow[vowcheck0]:
                num0+=1
                vowcheck0=0
            elif vowcheck0<vowcheck:
                vowcheck0+=1
            else:
                rework+=text[num0]
                num0+=1
                vowcheck0=0
        return rework

#19

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:
            str_output.append(i)
    return "".join(str_output)
print anti_vowel(text)