0% found this document useful (0 votes)
5 views2 pages

OOP Assignment

The document outlines an OOP assignment focused on inheritance, polymorphism, and exception handling in Python. It includes tasks to implement a class hierarchy with a base class 'Person' and derived classes 'Student' and 'Teacher', demonstrating polymorphism through overridden methods. Additionally, it requires handling exceptions in a method that calculates grades, along with a bonus task to integrate all concepts into a cohesive program.

Uploaded by

Ebiyo Faf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

OOP Assignment

The document outlines an OOP assignment focused on inheritance, polymorphism, and exception handling in Python. It includes tasks to implement a class hierarchy with a base class 'Person' and derived classes 'Student' and 'Teacher', demonstrating polymorphism through overridden methods. Additionally, it requires handling exceptions in a method that calculates grades, along with a bonus task to integrate all concepts into a cohesive program.

Uploaded by

Ebiyo Faf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

OOP Assignment: Inheritance, Polymorphism, and Exception Handling

Objective:

1. Understand and implement the concepts of inheritance and polymorphism.


2. Learn to handle exceptions in object-oriented programs.

Instructions:

1. Write the code in Python (or the language you are teaching).
2. Submit your code with appropriate comments.
3. Each task should be implemented as a separate class or function.

Tasks:

Task 1: Implement a Class Hierarchy with Inheritance

- Create a base class `Person` with the following attributes:


- `name` (string)
- `age` (integer)
- Add a method `display()` to the `Person` class that prints the name and age.
- Create a derived class `Student` that inherits from `Person`. Add the following attributes:
- `student_id` (string)
- `course` (string)
- Add a method `display()` to the `Student` class that overrides the base class method and
displays all the attributes.

Task 2: Demonstrate Polymorphism

- Create another derived class `Teacher` from `Person`. Add the following attributes:
- `employee_id` (string)
- `subject` (string)
- Add a method `display()` to the `Teacher` class that overrides the base class method and
displays all the attributes.
- Write a function `show_details(person: Person)` that accepts an object of type `Person` and calls
its `display()` method.
Task 3: Handle Exceptions

- Extend the `Student` class by adding a method `calculate_grade(marks: list)` that:


- Accepts a list of marks.
- Raises an exception if the list is empty or contains invalid data (e.g., non-numeric values).
- Calculates and returns the average grade if all values are valid.
- Handle exceptions properly and display a meaningful error message when an exception occurs.

Bonus Task:

- Create a small program that demonstrates how all the concepts (inheritance, polymorphism, and
exception handling) can work together.

You might also like