1 Task

Write a file named quadratic.py with a function named big_root which, if given (a, b, c), returns the more positive root of the quadratic equation

a x2 + b x + c = 0

Use the quadratic formula to solve this problem.

Also write a second function, small_root, which gives the other root of the equation.

You may assume we only give coefficients for which the answer is a real number, and that the first coefficient will be positive.

Neither function should print anything nor ask for any input. You should not have any code outside of these two functions.

2 Example Invocations

When you run quadratic.py, nothing should happen. It defines a function, it does not run it.

If in another file (which you do not submit) you write the following:

import quadratic

print(quadratic.big_root(1, -1, -1))
print(quadratic.small_root(1, -1, -1))

you should get the following output:

1.618033988749895
-0.6180339887498949

(don’t worry if your answer differs in the last few digits)

3 Thought Question

We won’t grade this, but what does your code do when you try to solve an equation with no real solutions?

print(quadratic.big_root(1, 1, 1))

If you want, feel free to also add the cubic formula or even (if you feel really ambitious) the quartic formula, but there isn’t a quintic formula.

4 Troubleshooting

Recall that .

Don’t remember the operators you need? See §3.3.1. Also, remember that in Python ^ is not the exponentiation operator (we won’t cover what ^ is; if you are curious, see §19.2.5).

Did you get the order of operations right? You could look them up, but adding parentheses never hurts.

There are two roots (because of the ± in the quadratic formula), but because q is always positive, one of them is always the biggest… no need for an if (though you may use one if you want to).

Have you tried other coefficients besides (1, -1, -1)?