collin.day.0 at gmail.com
Fri Dec 19 03:12:02 CET 2008
On Dec 18, 11:37 am, collin.da... at gmail.com wrote:
> I am trying to write a simple application to factor polynomials. I
> wrote (simple) raw_input lines to collect the a, b, and c values from
> the user, but I dont know how to implement the quadratic equation
> x = (-b +or- (b^2 - 4ac)^1/2) / 2a
> into python. Any ideas?
I completed the code:
from math import sqrt
# collect data
a = float(raw_input('Type a value: '))
b = float(raw_input('Type b value: '))
c = float(raw_input('Type c value: '))
# create solver
if b**2 - 4*a*c < 0:
return 'No real solution.'
sol1 = -1 * b + (sqrt(b**2 - 4*a*c)) / 2*a
sol2 = -1 * b - (sqrt(b**2 - 4*a*c)) / 2*a
return (sol1, sol2)
Thanks to everyone who helped...
This really expanded my knowledge on some of the mathematical
functions in Python.
More information about the Python-list