8 anti_vowel. Nice and easy solution:


#1

def anti_vowel(text):
x = ""
for char in text:
if char not in "aeiouAEIOU":
x = x + char
return x

           Just make sure to put it at the right indentation.

          If you have any suggestion please feel free to share.

#2

def scrabble_score(word):
    x = 0
    for char in word: 
        x = x + score[char.lower()]
    return x

The answer to 9. Scrabble_score with the same idea


#3

Nice! I took a super cheater route! I did the following:
def anti_vowel(text):
text = text.replace("a")
text = text.replace("e")
text = text.replace("i")
text = text.replace("o")
text = text.replace("u")
text = text.replace("A")
text = text.replace("E")
text = text.replace("I")
text = text.replace("O")
text = text.replace("U")
return text

Obviously your answer is what the designers of the problem were looking for.


#4

def anti_vowel(x):
new_str = " "
led = 0

for i in x:  
    for j in "aeiouAEIOU":
        if i == j:
           led = 1
           break
        else: 
            led = 0
        led += led        
    if led <1:
        new_str += i           
return new_str

print anti_vowel("Hey look Words!")

This prog really works, but mentor does'n accept it.
Youry? UKR


#5

You should make change!
def anti_vowel(text):
text = text.replace("a","")
text = text.replace("e","")
text = text.replace("i","")
text = text.replace("o","")
text = text.replace("u","")
text = text.replace("A","")
text = text.replace("E","")
text = text.replace("I","")
text = text.replace("O","")
text = text.replace("U","")
return text


#6
def anti_vowel(text):
    vowels = 'aeiouAEIOU'
    for letter in text:
        for vowel in vowels:
            if vowel == letter:
                letter = ""
    return text

That's the code I wrote but it's not working. That's not a solution but since this is the only anti_vowel thread I am posting here. Help please!


#7

@odrekci: Thing is that if the if statement is false, you should've added that character to the new string so it could be returned. Try making it different by checking if:

 vowel != letter

There you could use a new variable, suppose is new_String, and concatenate that character, who's not a vowel, to the new string to be returned.

Quote me if there's anything else I can help you with!

Best regards,
g4be

Edit: Also, another error will occur! Not only the if statement but the fact that is the condition is changed to *different even if you get the character who isn't a vowel and concatenating into the new string, you'll do that multiple times, each time per vowel.
So if the set is 'aeiouAEIOU' and the value in letter is C, you'll store C ten times, because that's the quantity of elements in the vowel set you're using, due to the fact that letter is not a vowel.
Such approach might not work, unless you change your idea.


#8

I saw that and I will probably do it in a diffrent way but can you tell me why my first code didn't work?
Was it because of the
letter = ""
If so, why exactly?


#9

@odrekci: I did edit my previous post so I'd ask you to take a look!
That approach might not work because even if it's a vowel or not, the value in the letter variable will continue the same and continue to be compared and executed for each element in the vowel set.
It would be possible to use two for loops in case the text was a list but this way you would still need to check each character.
The way you did doesn't seem to really work, sorry to say that.


#10

def anti_vowel(text):
for c in text:
if c in "aeiouAEIOU":
text=text.replace(c,"")
return text


#11

I've did that.

def anti_vowel(text):
c = "aeiouAEIOU"
result = ""
for i in range(len(text)):
if text[i] in c:
i =""
else:
result += text[i]
return result