Anti_vowel


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/2?curriculum_id=4f89dab3d788890003000096#

Oops, try again. Does your anti_vowel function take exactly one argument (a string)? Your code threw a "'str' object does not support item assignment" error.


Replace this line with your code. 
def anti_vowel(text):
    string=" "
    i=0
    n = len(text)
    while(i<n):
        if text[i] in "aeiouAEIOU":
            text[i]=" "
        else:
            text[i]=i
        i = i+1
        string = string + text[i]
            
    return string


#2

This is the line that raised the error first. Changed it to,

x = text[i]

Then this line raises the same error...

text[i] = " "

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 7, in anti_vowel
TypeError: 'str' object does not support item assignment

Changing that line to,

x = ""

fixes the raised exceptions and outputs correctly. There is still one tiny detail remaining...

string =  " "

It should rightly be just an empty string, ""

With these three adjustments,

def anti_vowel(text):
    string  = ""
    i = 0
    n = len(text)
    while(i < n):
        if text[i] in "aeiouAEIOU":
            x = ""
        else:
            x = text[i]
        string += x
        i += 1
            
    return string

print anti_vowel('The rain in Spain falls mainly in the plains.')

# 'Th rn n Spn flls mnly n th plns.'

#3

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