1:19 Trying to add "orange" to go with lemon. Text problem


class Fruit(object):
    """A class that makes various tasty fruits."""
    def __init__(self, name, color, flavor, poisonous):
        self.name = name
        self.color = color
        self.flavor = flavor
        self.poisonous = poisonous

    def description(self):
        if self.color[0] == "a" or "e" or "i" or "o" or "u":
            print "I'm an %s %s and I taste %s." % (self.color, self.name, self.flavor)
            print "I'm a %s %s and I taste %s." % (self.color, self.name, self.flavor)
    def is_edible(self):
        if not self.poisonous:
            print "Yep! I'm edible."
            print "Don't eat me! I am super poisonous."

lemon = Fruit("lemon", "yellow", "sour", False)
canteloupe = Fruit("canteloupe", "beige", "bland", True)
orange = Fruit("orange", "orange", "sweet", False)


Here is my code. Basically I am just trying to put "I am a yellow..." or "I am an orange..." for things that start with vowels. But no matter what I do both always print "I am an yellow/orange..."

Can someone help me out here? I tried - str(if self.color[0[)== etc but I cant get this to work.


print False or "e"


print bool("e")


if "e":
    print '"e" is truthy'
    print '"e" is falsy'

"e" is truthy


I'm sorry, I dont understand this at all. Could you elaborate please?


Why are you using self.color for your if statement to test if the first letter of the fruit is a vowel?


In the example the color is listed first. "I am a(n) "color" "fruit"...." so it would be "I am and orange orange..." and what not.


Oops, sorry 'bout that. Hmmm... print self.color[0] does print the first letter of the color but doesn't like the comparison for some reason. I also tried <> and switched the 'an' and 'a' words of the output but still had the same issue. Need to think on this some more.


Alright... after you do your first comparison

if self.color[0] == "a"

then you state

or "e" or "i" or "o" or "u":

so if you break it down with parentheses you would have

if (self.color[0] == "a") or ("e") or ("i") or ("o") or ("u"):

which would explain why it doesn't do the compare for the other 'vowels'. Is that enough of a hint?


No, it doesn't. I am sorry. I am not very smart.

EDIT: I suppose I could use a bunch of elif statements like
elif self.color == "a":
print "X"
elif self.color == "e"
print "X'
elif self.color == "i"
print "X"

So on but I feel like there is an easier way. I don't see what I am missing.


You are on the right track. One way to still use 'or' is make it all one statement.

    if self.color[0] == "a" or \
       self.color[0] == "e" or \
       self.color[0] == "i" or \
       self.color[0] == "o" or \
       self.color[0] == "u":

A cleaner way is to use 'in' to put it all on one line. This will test membership in a list
if self.color[0] in ["a", "e", "i", "o", "u"]: