Anti_vowel


#1

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

This is the correct code, but it's very long-winded.

def anti_vowel(text):
    word = ""
    for char in text:
        if char != 'A' and char != 'a' and char != 'O' and \
        char != 'o' and char != 'U' and char != 'u' and \
        char != 'E' and char != 'e' and char != 'i' and \
        char != 'I':
            word += char
    return word

However, why doesn't the below work?

def anti_vowel(text):
    vowels = ('a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U')
    word = ""
    for char in text:
        if char != vowels:
            word += char
    return word

#2

well, char is a single character, where vowels is a tuple. A tuple can't possible equal a single character string

you can use the in keyword to check if something is present in a list/tuple


#3

hmm understood.
Do you have any alternative method though? the first code is way too long


#4

I already gave you a hint fro an alternative method?


#5

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