Doubt in the "Change it up" exercise


#1

Here's my code for the exercise:

fruits = ['banana', 'apple', 'orange', 'tomato', 'pear', 'grape']

print 'You have...'
for f in fruits:
    if f[0] == 'a' or 'e' or 'i' or 'o' or 'u':
        print 'An', f
    else:
        print 'A', f
else:
    print 'A fine selection of fruits!'

The output on the console is the following:
You have...
An banana
An apple
An orange
An tomato
An pear
An grape
A fine selection of fruits!
None

I don't understand why the fruits which don't begin with a vowel get printed with the article "an" in front of them, whereas my code suggests that only fruits which begin with a vowel should have "an" in front of them in the output.

Any sort of help is appreciated. Thanks.


#2

Please post a link to this exercise. We're just as lost as you without it. Thank you.


#3

I don't think that's needed but here you go: https://www.codecademy.com/en/courses/python-beginner-en-cxMGf/2/5


#4

I do. Thank you for posting it.


#6

Your expression is evaluated like this:

(f[0] == 'a') or 'e' or 'i' or 'o' or 'u'

What do you think this evaluates to?

False or 'e'

And what happens if you convert 'e' to bool?

What happens if you do this?

if 'e':
    print 'hello'