-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.py
More file actions
49 lines (35 loc) · 854 Bytes
/
Copy pathoop.py
File metadata and controls
49 lines (35 loc) · 854 Bytes
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
class student:
def __init__(self, name, age, score):
self.name = name
self.age = age
self.score = score
def greet(self):
print(f"hi I am {self.name} and {self.age} years old.")
def passed(self):
return self.score > 50
s1 = student("abdu", 24, 66)
s2 = student("mike", 30, 40)
s1.greet()
print('passed:', s1.passed())
s2.greet()
print('passed:', s2.passed())
#inheritance
class person:
def __init__(self, name):
self.name = name
def speak(self):
print(self.name, 'says hello')
class teacher(person):
def teach(self):
print(self.name, 'is teaching now')
t = teacher('mr elias')
print()
t.speak()
t.teach()
#method overiding
class kids(person):
def speak(self):
print(self.name, 'says I have a homework')
k = kids('baby')
print()
k.speak()