-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonInheritanceExample.py
More file actions
38 lines (29 loc) · 1000 Bytes
/
PythonInheritanceExample.py
File metadata and controls
38 lines (29 loc) · 1000 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
# Replace ___ with your code
# create the Person class
class Person:
def __init__(self):
person_name = input("Enter name: ")
person_age = int(input("Enter age: "))
self.name = person_name
self.age = person_age
def display_info(self):
print(f"name: {self.name}")
print(f"age: {self.age}")
# derive the Student class from Person
class Student(Person):
# create the __init__() method
def __init__(self, student_id):
# create id attribute and assign student_id to it
self.id = student_id
# call the __init__ method of Person using super()
super().__init__()
# create the display_info() method
def display_info(self):
# call display_info() of Person using super()
super().display_info()
# print the id attribute
print(f"id: {self.id}")
# create an object of Student with 12 as argument
s1 = Student(12)
# call display_info() using the object
s1.display_info()