-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestme.py
More file actions
68 lines (53 loc) · 2.3 KB
/
testme.py
File metadata and controls
68 lines (53 loc) · 2.3 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class man(object):
# name of the man
name = ""
def __init__(self, P_name):
""" Class constructor """
self.name = P_name
print("Here comes " + self.name)
def talk(self, P_message):
print(self.name + " says: '" + P_message + "'")
def walk(self):
""" This let an instance of a man to walk """
print(self.name + " walks")
# This class inherits from Man class
# A superman has all the powers of a man (A.K.A. Methods and Properties in our case ;-)
class superman(man):
# Name of his secret identity
secret_identity = ""
def __init__(self, P_name, P_secret_identity):
""" Class constructor that overrides its parent class constructor"""
# Invokes the class constructor of the parent class #
super(superman, self).__init__(P_name)
# Now let's add a secret identity
self.secret_identity = P_secret_identity
print("...but his secret identity is '" + self.secret_identity + "' and he's a super-hero!")
def walk(self, P_super_speed = False):
# Overrides the normal walk, because a superman can walk at a normal
# pace or run at the speed of light!
if (not P_super_speed):
super(superman, self).walk()
else:
print(self.secret_identity + " run at the speed of light")
def fly(self):
""" This let an instance of a superman to fly """
# No man can do this!
print(self.secret_identity + " fly up in the sky")
def x_ray(self):
""" This let an instance of a superman to use his x-ray vision """
# No man can do this!
print(self.secret_identity + " uses his x-ray vision")
# Declare some instances of man and superman
lois = man("Lois Lane")
jimmy = man("Jimmy Olsen")
clark = superman("Clark Kent", "Superman")
# Let's puth them into action!
print("\n--> Let's see what a man can do:\n")
jimmy.walk()
lois.talk("Oh no, we're in danger!")
print("\n--> Let's see what a superman can do:\n")
clark.walk()
clark.talk("This is a job for SUPERMAN!")
clark.walk(True)
clark.fly()
clark.x_ray()