-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-Animal.py
More file actions
executable file
·50 lines (45 loc) · 1.11 KB
/
06-Animal.py
File metadata and controls
executable file
·50 lines (45 loc) · 1.11 KB
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
49
50
class Animal(object):
def __init__(self,name,health):
self.name = name
self.health = health
def walk(self):
self.health -= 1
return self
def run(self):
self.health -= 5
return self
def displayHealth(self):
print self.health
return self
animal = Animal("anim",100)
animal.walk()
animal.walk()
animal.walk()
animal.run()
animal.run()
animal.displayHealth()
class Dog(Animal):
def __init__(self,name,hp):
super(Dog,self).__init__(name,hp)
self.health = 150
def pet(self):
self.health += 5
class Dragon(Animal):
def __init__(self,name,hp):
super(Dragon,self).__init__(name,hp)
self.health = 170
def fly(self):
self.health -= 10
return self
def displayHealth(self):
super(Dragon,self).displayHealth()
print "I am a dragon"
dog = Dog("sparky",0)
dog.walk().walk().walk().run().run().pet()
dog.displayHealth()
#dog.fly()
dragon = Dragon("spike",0)
dragon.run().run().fly().fly().fly().displayHealth()
newAnimal = Animal("anim2",123)
#newAnimal.pet()
#newAnimal.fly()