Quadratic formula is not working half the time?

I have made a quadratic formula in python, it looks like this:

import math
a, b, c = input("Enter a, b and c: ").split()
a, b, c = int(a), int(b), int(c)
print((0-b + ((b**2) - (4*a*c))**0.5)/2*a)
print((0-b - ((b**2) - (4*a*c))**0.5)/2*a)

On some questions it works, but when you input "5 9 1" it does not give the correct answer.

Upvotes: 0

Views: 47

Answers (1)

Frank
Frank

Reputation: 1785

You have to put 2*a into parentheses in the formula:

(...)/(2*a)

In an expression like

(...)/2*a

you first divide by 2 and then multiply by a.

Upvotes: 4

Related Questions