Question: 1 . Create a Python application that models a basic school system. The system should include two types of people: students and teachers. Each person

1. Create a Python application that models a basic school system. The system should include two types of people: students and teachers. Each person should have a name and age stored in a dictionary as their attributes, e.g.{name: name, age: age}. Teachers have an additional attribute, the subject they teach, while students have a list of grades. Use inheritance to avoid code duplication.
In your program, you should have three classes [10 points for each class]:
a. Person Class:
Create a base class called Person that initializes with a name and age.
Store the attributes in a dictionary within the class.
Implement a method get_details() that returns the person's details as a string.
b. Student Class:
Create a Student class that inherits from Person.
Add an attribute called grades for storing a list of grades (e.g.,[90,80,85]) in the initializer. This should also be stored together with the name and the age in the attributes dictionary.
Implement a method calculate_average_grade() that calculates and returns the student's average grade.
Override the get_details() method to include average grade information in the returned string.
c. Teacher Class:
Create a Teacher class that inherits from Person.
Add an attribute called subject for storing the subject they teach in the initializer. This should also be stored together with the name and the age in the attributes dictionary.
Override the get_details() method to include the subject information in the returned string.
In your main program:
Instantiate a few Student and Teacher objects with various details.
Call the get_details() method on each instance and print the results to demonstrate that your system works.

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!