-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectOriented.py
81 lines (61 loc) · 2.12 KB
/
ObjectOriented.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
'''
class StanfordCourse:
def __init__(self, department, code, title):
self.department = department
self.code = code
self.title = title
# p = StanfordCourse("CS","Python","Intro to python")
class StanfordCSCourse(StanfordCourse):
def __init__(self, department, code, title, recorded=False):
super().__init__(department, code, title)# or StanfordCourse.__init__(self,department, code, title)
self.is_recorded = recorded
a = StanfordCourse("CS", "106A", "Programming Methodology")
b = StanfordCSCourse("CS", "106B", "Programming Abstractions")
x = StanfordCSCourse("CS", "106X", "Programming Abstractions", recorded=True)
# print(a.code) # => "106A"
# print(b.code) # => "106B"
# type(a)
# print(isinstance(a, StanfordCourse))
# print (isinstance(b, StanfordCourse))
# print(isinstance(x, StanfordCourse))
# print(isinstance(x, StanfordCSCourse))
# # print(issubclass(x, StanfordCSCourse))
# print(issubclass(StanfordCSCourse, StanfordCourse)) ****************
# print(type(a) == type(b))
# print(type(b) == type(x))
# print(a == b)
# print(b == x)
'''
class StanfordCourse:
def __init__(self, department, code, title):
self.department = department
self.code = code
self.title = title
def mark_attendance(self, *students):
self.students = students
for n in students:
print(n,"is here ")
def is_present(self, student):
self.student = student
if self.student in self.students:
return True
else:
return False
class StanfordCSCourse(StanfordCourse):
def __init__(self, department, code, title, recorded=False):
super().__init__(department, code, title)# or StanfordCourse.__init__(self,department, code, title)
self.is_recorded = recorded
p = StanfordCSCourse("CS","41","Computer Science")
p.mark_attendance("James","Rieder","Allen","Grace")
print(p.is_present("James"))
# Case (A)
try:
print("Try")
raise Exception('An on-purpose exception.')
except Exception as exc:
print(exc)
else:
print("Else")
finally:
print("Finally")