티스토리 뷰
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) #from first one, name, colour, flavor and poisonus
lemon.description()
lemon.is_edible()class Triangle(object):
number_of_sides = 3
def __init__(self, angle1, angle2, angle3):
self.angle1 = angle1
self.angle2 = angle2
self.angle3 = angle3
def check_angles(self):
if self.angle1 + self.angle2 + self.angle3 == 180:
return True
else:
return False
class Equilateral(Triangle):
angle = 60
def __init__(self):
self.angle1 = 60
self.angle2 = 60
self.angle3 = 60
my_triangle = Triangle(60, 70, 50) #Put angle value
print my_triangle.number_of_sides #print 3
print my_triangle.check_angles() #print True
print my_triangle.angle1 #print 60
print my_triangle.angle2 #print 70
print my_triangle.angle3 #print 50
my_triangle = Equilateral() #put value of 60 each
print my_triangle.check_angles() #print 3
print my_triangle.angle1 #print 60
print my_triangle.angle2 #print 60
print my_triangle.angle3 #print 60'IT > Python: Codecademy' 카테고리의 다른 글
| 12 File Input and Output and Finish course (0) | 2018.03.19 |
|---|---|
| Sec10: bit calculator (0) | 2018.03.08 |
| 10 Advanced Topics in Python (0) | 2018.03.07 |
| 9 Exam Statistics (0) | 2018.03.06 |
| 8 Loop (0) | 2018.02.28 |
댓글