Multiple 'or' Operators


#1


https://www.codecademy.com/en/courses/python-beginner-2W5v7/1/5?curriculum_id=4f89dab3d788890003000096


I was getting a little off topic trying to make words starting with vowels work with the code. I used a bunch of or statements and in testing the only words starting with 'a' are marked as true. Why doesn't this work?
(the parentheses were added in debugging; didn't fix it)

Also is there (rather what is) a better way of doing this?


pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    word = original.lower()
    first= word[0]
    
    if first == ("a" or ("e" or ("i" or ("o" or "u")))):
        new_word = word + "w" + pyg
        print new_word
        
    else:
        new_word = word[1:len(word)] + first + pyg
        print new_word


else:
    print 'empty'


#2

or returns the left side if the left side is truthy, otherwise it returns the right side.

This does not have the effect of comparing multiple expressions on the right side to the left side, the two sides are not compared to each other at all, and here you're trying to compare to something that isn't part of that expression at all (outside the parentheses)

condition1 or condition2

0 or 5        # 5, but this is probably not how you should use it
False or 'e'  # can you tell from the above example what this evaluates to?
'o' or 'u'

#3

@ionatan
Ok I realized where I messed up.

if first == "a" or first == "e" or first == "i" or first == "o" or first == "u":

This is what I was trying to do, but it is still tedious. is there a better way to do this?


#4

Stick the values to compare to into some data structure and loop through it, comparing each one. Since it's single characters, a string is appropriate. For the looping part, there's the in-operator