Anti Vowel


#1



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


SyntaxError: unexpected character after line continuation character


Why is the colon at the end of the if statement wrong?


def anti_vowel(text):
    string=""
    for item in text:
        if item=='a' or 'e' or 'i' or 'o' or 'u' or 'A' or 'E'\          or  'I' or 'O' or 'U':
            string=string
        else:
            string=string+item
        
    return string


#2

problem 1:

 if item=='a' or 'e' or 'i' or 'o' or 'u' or 'A' or 'E'\          or  'I' or 'O' or 'U'

solution : You do not need continuation character,remove it.

problem 2:
When you loop through each of the items, you're assigning your string '', so effectively if it has stored some letters,It is just resetting all things again.
string=string

solution:
use this --
string = string + ''
OR
string += '' # augmented expression

I hope it helps.

Ps: I see youre using
if item=='a' or 'e' or 'i' or 'o' or 'u' or 'A' or 'E'\ or 'I' or 'O' or 'U':
Instead doing this, define a local list at the starting of your function and add all the vowels to it.

local_list = ['a','e','i','o','u','A','E','I','O','U']

then use it like this--

if item in local_list:
It makes your code more readable and clean.

I hope it helps.:slight_smile:


#3

Thank you @greentreemee


#5

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