Objective
Develop a Python program that asks the user for three names and stores them in a list of Person objects. Two of them are students and one is a teacher.
Instructions
- Create a class called
Personwith an attributename, a constructor that receives the name and the special method__str__. - Create two classes that inherit from
Person:StudentandTeacher. Each one has a constructor that calls the constructor of the parent class withsuper().__init__(). - The
Studentclass has the methodstudy(), which displays that the student is studying. TheTeacherclass has the methodexplain(), which displays that the teacher is explaining. - Ask the user for the name of the teacher and the names of the two students.
- Go through the list and call
explain()orstudy()according to the type of each object. Notice how inheritance and polymorphism make the code more organized.
Juan
Sara
Carlos
Explain
Study
Study
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise