Project # 1 / CSC-120 Due: Wednesday, October 21, 2020 by 08:00:00 EDST Your mission is to write a Python function which �nds roots of polynomials up to degree 2. More speci�cally, your function...

Please follow the instructions in the file titled "cscProject_1" and use the file titled "project1" as a template.


Project # 1 / CSC-120 Due: Wednesday, October 21, 2020 by 08:00:00 EDST Your mission is to write a Python function which �nds roots of polynomials up to degree 2. More speci�cally, your function should accept three real inputs, let us call them a, b, and c, and respond with all solutions of the equation ax2 + bx+ c = 0 for the given values of a, b, and c. Here are further speci�cations: I. Your python program should be in a �le named project_1.py. Within this �le, there should be the following six functions. A. get_inputs: This function should request the inputs a, b, and c from the user and output them as a tuple. B. is_number: This function should take one value x as an input, and test whether or not that value is numeric. It should return True if so, and it should return False if not. C. constant_solver: This function should take one number a as an input, and �nd and report all solutions to the equation a = 0. D. linear_solver: This function should take two numbers a and b as inputs, with a 6= 0, and �nd and report all solutions to the equation ax+ b = 0. E. quadratic_solver: This function should take three numbers a, b, and c as inputs, with a 6= 0 and �nd and report all solutions to the equation ax2 + bx+ c = 0. F. polynomial_solver: This function should take three numbers a, b, and c as inputs, and determine which of constant_solver, linear_solver, or quadratic_solver should be deployed to solve the equation ax2 + bx+ c = 0. It should then deploy that function. II. The program should gracefully handle each of the following cases: A. The case a 6= 0. The program should give its response like this: There are two solutions: x = #### and x = ####. B. The case a = 0 6= b. In this case, the equation is in fact linear, and there is only one solution. The program should give its response like this: There is one solution: x = ####. C. The case a = b = 0 6= c. In this case, there is no solution. The program should give its response like this: There is no solution. D. The case a = b = 0 = c. In this case, there are no non-solutions. The program should give its response like this: Every complex number is a solution. III. A. When there are two distinct real solutions, the smaller one should be �rst, and the larger second. B. When there are two complex solutions, they must be complex conjugates; the one with the negative imaginary part should come �rst, and the other second. C. When there is one repeated solution, list it twice. IV. All answers should be rounded to exactly four decimal places. V. Examples: A. polynomial_solver(1, 4, 3) gives the following response: There are two solutions: x = -3.0000 and x = -1.0000. 1 B. polynomial_solver(2, -8, 8) gives the following response: There are two solutions: x = 2.0000 and x = 2.0000. C. polynomial_solver(1, 1, 1) gives the following response: There are two solutions: x = -0.5000-0.8660j and x = -0.5000+0.8660j. (Note in this example that Python automatically formats the complex numbers for you, and uses j rather than i for √ −1.) D. polynomial_solver(0, 7, 4) gives the following response: There is one solution: x = -0.5714. E. polynomial_solver(0, 0, 1) gives the following response: There is no solution. F. polynomial_solver(0, 0, 0) gives the following response: Every complex number is a solution. 2 def get_inputs(a, b, c): # Desc: Requests 3 coefficients # Inputs: a, b, c # Outputs: A tuple of three values (presumed to be numbers) print('Hello, welcome to the polynomial solver.') print('Please enter a, b, and c to see the solutions of ax^2 + bx + c = 0.') a = input('Enter a: ') b = input('Enter b: ') c = input('Enter c: ') coeff = (a, b, c) print(coeff) def is_number(x): # Desc: Checks if input is numerical or not # Inputs: x (can be of any type) # Outputs: bool (True if x is numerical, false otherwise) try: float(x) return(True) except ValueError: return(False) def constantSolver(a): # Desc: Solves the constant equation a = 0 for x # Inputs: a # Outputs: the solution to a = 0, float return(-c / b) def linear_solver(a, b): # Desc: Solves the linear equation ax + b = 0 for x # Inputs: a and b (both numerical, a is assumed nonzero) # Outputs: the solution to ax + b = 0, float return(-b / a) def quadratic_solver(a, b, c): # Desc: Solves the quadratic equation ax^2 + bx + c = 0 for x # Input: a, b, and c (all numerical, a is assumed nonzero) # Outputs: the solutions to ax^2 + bx + c = 0, floats from math import sqrt return(-b + sqrt(b ** 2 - 4 * a * c)) / (2 * a)
Oct 21, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here