'str' object does not support item assignment


#1



I don't understand what's wrong with this.


def anti_vowels(text):
    vowels = "aeiouAEIOU"
    for i in range(0,len(text)):
        for text[i] in vowels:
            text[i] = ""
    return Text

print anti_vowels("helloworld")


#2

well, you made so many choices that are making your code harder and harder there are simpler ways to go trough this ;
first there is no need to combine two for loop because you need just to iterate over the variable vowels and check if one of the letters in it exist in you text ,the input of your function,
besides you should be careful with the words you type like this one you don't have anything called Text
to sum up, it's a good idea to familiarize yourself with the code bellow it's really simple then try another time with your own ideas :wink: :

def anti_vowel(text):
    vowels="ouiaeOUIAE"
    for x in vowels:
        text=text.replace(x,'')
    return text 
    print text
print anti_vowel('adnan')

#3

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