I've identified a code snippet that calculates the quadratic formula given points a, b, and c. However, the current implementation involves reduced readability as well as documentation clarification issues.
The code includes separate functions for calculating Euclidean and Manhattan distances that could be jointed by one function, with each function containing duplicated logic when performing distance calculations each step.
The code does not have proper documentation for the function's purpose, parameters, and the return values. The code also should have more descriptive variable names and clarity behind the example.
Goals for Refactoring:
Refactoring the code by creating descriptive variable names.
Improve code readability by providing proper documentation on function purpose, parameters, and return values.
Improve readability further by adding explanations to example's clarity.
Below is the attached code snippet of the issue.
#Keith Del Rosario
#Task 2.2 Code Snippet
import cmath
def quadratic_formula(a, b, c):
discriminant = b**2 - 4*a*c
root1 = (-b + cmath.sqrt(discriminant)) / (2*a)
root2 = (-b - cmath.sqrt(discriminant)) / (2*a)
return root1, root2
# Example usage:
a = 1
b = -3
c = 2
root1, root2 = quadratic_formula(a, b, c)
print("Root 1:", root1)
print("Root 2:", root2)
I've identified a code snippet that calculates the quadratic formula given points a, b, and c. However, the current implementation involves reduced readability as well as documentation clarification issues.
The code includes separate functions for calculating Euclidean and Manhattan distances that could be jointed by one function, with each function containing duplicated logic when performing distance calculations each step.
The code does not have proper documentation for the function's purpose, parameters, and the return values. The code also should have more descriptive variable names and clarity behind the example.
Goals for Refactoring:
Refactoring the code by creating descriptive variable names. Improve code readability by providing proper documentation on function purpose, parameters, and return values. Improve readability further by adding explanations to example's clarity.
Below is the attached code snippet of the issue.