Anti-vowel


#1




I have this error message, Oops, try again. Does your anti_vowel function take exactly one argument (a string)? Your code threw a "string indices must be integers, not str" error.


Please help, i would like to understand what is wrong in my code


This is what my code looks like:
def anti_vowel(text):
    vowel=("aeiouAEIOU")
    word=''
    x=0
    y=0
    while x<=(len(text)-1):
        for y in vowel:
            if text[x]!=vowel[y]:
               return word.append(text[x])
        x+=1 
    return word.join()


#2

While loops don't keep a loop count, necessarily. You are probably trying to grab it using x which you define as a string somewhere.


#3

This is just how I did it, I'm sorry that I can't learn you to do this with the while- loop.

As first, you should not set your vowel- variable equal to a random string. Its value could be text- parameter treated by str() method. As secondary, remove your variables x and y. Using while loop isn't recommended in this kind of code, so remove the while- loop too. After your empty string, word, you should do a list, that includes all the vowels (I call the list as vowels) that are

"a", "e", "u", "o" and "i"

Just loop trough vowel, and check if there are lowercase letters in your word.

if char.lower() in vowels:

Last thing, add an else- statement, that adds char to word. Return the result.


#4

Thank you papusalaatti but i would like to understand what is the problem in the code,
And 825orion, i tried some "fixes" in the if statement, but it still isnt working, this is what i have now:
def anti_vowel(text):
vowel=("aeiouAEIOU")
word=''
y=vowel(0,11)
x=0
z=text(0,len(text)-1)
while x<=(len(text)-1):
for y in vowel:
if z!=y:
word.append(z)
x+=1
return word.join()

And this is the error i am getting:
Oops, try again. Does your anti_vowel function take exactly one argument (a string)? Your code threw a "'str' object is not callable" error.

Thanks!!


#5

I don't properly speaking understand what your while- loop tries to do. :neutral_face:
Sorry.


#6

'nuf said.

That aside, we are given a text object. Text is iterable. We are also given a native operator, in, which is iterative. So we can manually iterate the text and let in iterate the secondary object.


#8

To Python this looks like a tuple with one element. You're making your job harder by wrapping in parens. Better to just write it as a plain string with no container.

vowel = 'aeiouAEIOU'

We won't be using this, but next time you wish to access a member of a tuple, treat it like a list:

y = vowel[0][0]    # first element, first letter

Go back to the drawing board, this time using a plain string and see if the logic doesn't unfold rather easily.


#10

thanks mtf.
very helpfull, i will try to make it work


#11

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