logo CodeStepByStep logo

quadratic

Language/Type: Python math parameters

Write a function named quadratic that solves quadratic equations and prints their roots. Recall that a quadratic equation is a polynomial equation in terms of a variable x of the form ax2 + bx + c = 0. Here are some example equations and their roots:

  • x2 - 7x + 12: x = -4, x = -3
  • x2 + 3x + 2: x = -2, x = -1

Your function should accept the coefficients a, b, and c as parameters and should print the roots of the equation in the following format. (You may assume that the equation has two real roots, though mathematically this is not always the case.) For example, the call of quadratic(1, -7, 12) should print:

First root = 4.0
Second root = 3.0
Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.