-
Notifications
You must be signed in to change notification settings - Fork 0
/
student_teacher.py
48 lines (35 loc) · 1.13 KB
/
student_teacher.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
class Person(object):
"""
Returns a '''Person''' object with given name.
"""
def __init__(self, name):
self.name = name
def get_details(self):
"Returns a string containing name of the person"
return self.name
class Student(Person):
"""
Returns a '''Student''' object, takes 3 arguments, name, branch, year.
"""
def __init__(self, name, branch, year):
Person.__init__(self, name)
self.branch = branch
self.year = year
def get_details(self):
"Returns a string containing student's details."
return "%s studies %s and is in %s year." % (self.name, self.branch, self.year)
class Teacher(Person):
"""
Returns a '''Teacher''' object, takes a list of strings (list of papers) as argument.
"""
def __init__(self, name, papers):
Person.__init__(self, name)
self.papers = papers
def get_details(self):
return "%s teaches %s" % (self.name, ', '.join(self.papers))
person1 = Person('Sachin')
student1 = Student('Meet', 'EE:S', 2015)
teacher1 = Teacher('Prashad', ['C', 'C++', 'Python'])
print person1.get_details()
print student1.get_details()
print teacher1.get_details()