Created
September 23, 2013 16:41
-
-
Save wehappyfew/6673338 to your computer and use it in GitHub Desktop.
codecademy python class exmaple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | |
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." | |
else: | |
print "Don't eat me! I am super poisonous." | |
lemon = Fruit("lemon", "yellow", "sour", False) | |
lemon.description() | |
lemon.is_edible() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment