This project is an advanced equation solver implemented in Python, supporting both linear and quadratic equations. It leverages object-oriented programming principles such as encapsulation, abstraction, and subclass initialization. By using abstract base classes (ABC
), it ensures that all equation types follow a structured implementation. The project also utilizes the re
module to enhance equation formatting. Additionally, this project was a part of the Scientific Computing with Python certification on FreeCodeCamp, where I learned about object-oriented programming and class inheritance in Python.
- Encapsulation: Data hiding is maintained through structured class attributes and methods.
- Supports Linear & Quadratic Equations: Implements
LinearEquation
andQuadraticEquation
classes. - Abstract Base Class: Uses an
Equation
class as a blueprint with abstract methods. - Automatic Subclass Validation: Implements
__init_subclass__
to enforce required attributes. - Equation String Formatting: Uses the
re
module for clean equation representation. - Solving & Analysis: Computes equation solutions and provides additional insights such as slopes, intercepts, and concavity.
- Implements an abstract base class (
ABC
) to enforce method definitions in subclasses. - Stores equation coefficients in a dictionary where keys represent the power of
x
. - Encapsulates equation logic by restricting direct modification of coefficients.
- Includes
__str__
for formatted equation output usingre.sub
to remove unnecessary coefficients.
- Ensures that every subclass has
degree
andtype
attributes. - Raises an error if these attributes are missing, preventing improper subclass definitions.
- This helps maintain consistency and avoid runtime errors.
- Used in the
__str__
method to remove unnecessary1
coefficients (e.g.,1x
→x
). - Ensures a cleaner and more readable equation representation.
lin_eq = LinearEquation(2, 3)
print(solver(lin_eq))
Output:
-----Linear Equation------
2x +3 = 0
--------Solutions--------
x = -1.500
---------Details---------
slope = 2.000
y-intercept = 3.000
quadr_eq = QuadraticEquation(1, 2, 1)
print(solver(quadr_eq))
Output:
---Quadratic Equation---
x**2 +2x +1 = 0
-------Solutions-------
x = -1.000
--------Details--------
concavit = upwards
min = (-1.000, 0.000)
- Python 3.x
- Uses built-in modules (
abc
,re
).
This project was developed as an exploration of object-oriented programming and mathematical computation in Python and was also part of the freeCodeCamp certification program.