Objective
Develop a Python program made of three classes: Person, Student and Teacher. The Student and Teacher classes inherit from the base class Person.
Instructions
- The
Personclass has two methods:greet(), which displaysHello!, andset_age(age), which sets the age of the person. - The
Studentclass has the methodstudy(), which displaysI'm studying, and the methodshow_age(), which displaysMy age is x years. - The
Teacherclass has the methodexplain(), which displaysI'm explaining. - Create a test class called
StudentTeacherTestwith amainmethod that:
- Creates a Person and greets. - Creates a Student, sets an age, greets, shows the age and studies. - Creates a Teacher, sets an age, greets and explains.
Input and output format. Read, with no prompts, the age of the student and then the age of the teacher (one per line). The program prints, one per line: Hello! (person), Hello!, My age is X years, I'm studying (student), Hello!, I'm explaining (teacher).
21
30
Hello!
Hello!
My age is 21 years
I'm studying
Hello!
I'm explaining
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise