Question: Create a new Python script named inheritance.py . Define a class named 'Person'. The class should have the following attributes: 'name', 'age', and 'country'. Add

Create a new Python script named inheritance.py.
Define a class named 'Person'.
The class should have the following attributes: 'name', 'age', and 'country'.
Add a method to the 'Person' class named 'introduce_yourself'.
This method should print a string in the format: "Hello, my name is [name]. I'm [age] years old, and I'm from [country]."
Create a 'Student' class that inherits from the 'Person' class.
The 'Student' class should have additional attributes: 'major' and 'gpa'.
Define a method called 'study' in the 'Student' class that prints a message: "[name] is studying [major] with a current GPA of [gpa]."
Create another class called 'Staff' that also inherits from the 'Person' class.
The 'Staff' class should have additional attributes: 'position' and 'department'.
Define a method called 'work' in the 'Staff' class that prints a message: "[name] works as a [position] in the [department] department."
Now, create a 'Person' object, a 'Student' object, and a 'Staff' object, all with appropriate attributes.
Call the 'introduce_yourself' method on all three objects.
Additionally, call the 'study' method on the 'Student' object and the 'work' method on the 'Staff' object.
Make sure your code runs without errors and produces the expected output.
After you have completed and tested your code, submit the inheritance.py file on Canvas.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!