--- layout: exercise permalink: /Modules/Python/Warmup/Exercise title: "CS377: Database Design - Quadratic Formula in Python" language: "python" info: points: 3 instructions: "Write a function that computes one of the roots of a quadratic equation. In addition to multiplying b by itself, you can compute b*b using the b** with the ** operator. The math.sqrt() method takes a single parameter, which is the number whose root should be computed, and returns the result. Now complete the code to compute one of the roots of the quadratic formula" goals: - To write mathematical expressions in Python - To write a function that computes an expression and returns its result canvasasmtid: "125423" canvaspoints: "3" processor: correctfeedback: "Correct!!" incorrectfeedback: "Try again" submitformlink: false feedbackprocess: | var pos = feedbackString.trim(); correctcheck: | pos.includes("3,1") || pos.includes("3.0,1.0") files: - filename: "quadratic.py" name: driver ismain: false isreadonly: false isvisible: true code: | import math def get_quadratic_roots(a, b, c): """ Compute the right root of of the quadratic equation f(x) = ax^2 + bx + c """ return 0 # This is a default value - filename: "main.py" ismain: true name: main isreadonly: true isvisible: true code: | # Run some tests on the method print(get_quadratic_roots(1, -1, -6), end=',') print(get_quadratic_roots(1, 0, -1)) --- ## Quadratic Formula For reference, the quadratic formula is: \\[\frac{-b \pm \sqrt{(b^{2} - 4ac)}}{2a}\\] given an equation: \\[ax^{2} + bx + c = 0\\] In this exercise, you can simply compute one of the roots, as follows: \\[\frac{-b + \sqrt{(b^{2} - 4ac)}}{2a}\\] ## Attribution Developed by [Prof. Chris Tralie](https://www.ursinus.edu/live/profiles/4502-christopher-tralie)