-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance.py
47 lines (28 loc) · 836 Bytes
/
Inheritance.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
#Methods
class fighter(object):
"""docstring for fighter"""
def __init__(self, name):
self.name = name
self.health = 100
self.damage = 10
def attack(self, other):
other.health -= self.damage
print("{}: attacks {}!".format(self.name, other.name))
print("{}: losses {} healht point!".format(other.name, self.damage))
def __str__(self): #String represenation
return "{}: {}".format(self.name, self.health)
Frank = fighter("Frank")
James = fighter("James")
print(Frank)
print(James)
James.attack(Frank)
print(Frank)
class Boxer(fighter):
def heal(self):
self.health += 10
boxer_frank = Boxer("Boxer_Frank") #Inherit from fighter class
print(boxer_frank)
print("Health points:", boxer_frank.health)
print("Damage points:",boxer_frank.damage)
boxer_frank.heal()
print("Healing power", boxer_frank)