TASK: In this assignment, you will expand on your understanding of Python classes, objects, methods, and attributes to further explore inheritance. You will create a parent Person class similar to last week and then two additional child classes (Student and Staff) that inherit attributes and methods from the parent class.
Your Person class should have the following attributes and methods:
- Attributes
name (string): A string that contains the individual’s name.age (integer): An integer containing the individual’s age.country (string): A string containing the individual’s country.
- Methods
__str__(): This method should return a string with the object's information in the format: “NAME is AGE years old and is from COUNTRY.”
Your Student class should inherit all of the attributes and methods of the Person class. The Student class should have the following additional attributes and methods:
- Attributes
major (string): A string that contains the individual’s major.gpa (float): A float containing the individual’s grade point average.
- Methods
study(): This method should return a string in the format: “[name] is studying [major] with a current GPA of [gpa].”
Finally, your Staff class should inherit all of the attributes and methods of the Person class. The Staff class should have the following additional attributes and methods:
- Attributes
position (string): A string that contains the individual’s current position.department (string): A string containing the individual’s department.
- Methods
work(): This method should return a string in the format: “[name] works as a [position] in the [department] department.”
This assignment can grade itself! To setup the autograding, you should do the following:
- Clone this file to your local machine using the command
git clone PASTE_URL_HERE- Open the downloaded file in your VS Code editor.
- In the left hand sidebar, press the "Testing" menu represented by the picture of a flask.
- Click "Configure Python Tests".
- You'll have two options to select. Select pytest.
- Select the folder where the tests live. You can simply select
. Root directory. - You can now run the tests by pressing the play icon. A passing test will get a ✅ and a failing test will get a ❌.
- Run the tests as you code and by the end it should be all ✅ if you have followed the specifications for this assignment!
Person- Name: "Billy"
- Age: 17
- Country: "Canada"
Student- Name: "John"
- Age: 17
- Country: "Canada"
- Major: "Computer Science"
- GPA: 3.5
Staff- Name: "Jane"
- Age: 30
- Country: "USA"
- Position: "Professor"
- Department: "Computer Science"
test_can_create_person: Tests that aPersonobject can be created with the values provided above.test_person_string: Tests that thePersonobject from the previous test produces the following__str__method outputBilly is 17 years old and is from Canada."test_student_inheritance: Tests that aStudentobject can be created and that it inherits properties/methods from thePersonclass.test_student_attributes: Tests that theStudentprovided above has set each attribute correctly.test_student_study: Tests that thestudy()method for the createdStudentobject returns the string"John is studying Computer Science with a current GPA of 3.5."test_staff_inheritance: Tests that aStaffobject can be created and that it inherits properties/methods from thePersonclass.test_staff_attributes: Tests that theStaffprovided above has set each attribute correctly.test_staff_work: Tests that thework()method for the createdStaffobject returns the string"Jane works as a Professor in the Computer Science department."
