-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst classes.py
52 lines (36 loc) · 1010 Bytes
/
first classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# first classes
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()
# Animals
class Animal(object):
"""Makes cute animals."""
is_alive = True
health="good"
def __init__(self, name, age):
self.name = name
self.age = age
# Add your method here!
def description(self):
print( self.name )
print(self.age)
hippo=Animal('Popi', 6)
sloth=Animal('suzi', 5)
ocelot=Animal('Kozer', 7)
print (hippo.health)
print (sloth.health)
print (ocelot.health)