Question: Directions for Lab: quadratic.py Follow the directions at PyCharm Debugging. We have provided starter code at quadratic.py ; use this instead of the Solver class
Directions for Lab: quadratic.py
Follow the directions at PyCharm Debugging. We have provided starter code at quadratic.py; use this instead of the Solver class version on the PyCharm Debugging webpage. Read over the PyCharm Debugging webpage, and demonstrate that you can step through the code and view the d variable prior to the square root function call. Explain the solve() code to your duck, and determine what changes are required to fix the code. Modify code as needed, and submit the code to zyLab.
GIVEN CODE FOR quadratic.py :
import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if __name__ == '__main__': # This will work with given code # x^2+3x + 2 =0 results = solve(1,3,2) print("Result of x^2+2x + 3 =0: "+str(results)) # This does not work with given code # x^2+2x + 3 =0 results = solve(1,2,3) print("Result of x^2+2x + 3 =0: "+str(results)) while True: print() print("Input coefficients of quadratic equation: (ctrl-C to quit)") a = int(input("a: ")) b = int(input("b: ")) c = int(input("c: ")) result = solve(a, b, c) print(result)
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
