On Dec 18, 9:40 pm, "J. Cliff Dyer" <j...@sdf.lonestar.org> wrote: > On Thu, 2008-12-18 at 11:52 -0800, eric wrote: > > On Dec 18, 8:37 pm, collin.da...@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? > > > with numpy: > > from numpy import * > > > s=[1,-1] > > x = -b+s*sqrt( b**2-4*a*c )/(2*a) > > > Eric > > Without the Nump. > > def polynomial(a, b, c): > N = ((b**2 - 4*a*c)**.5) / 2*a > return (-b + N, -b - N)
there is a little mistake in your formula : def roots_of(a, b, c): N = ((b**2 - 4*a*c)**.5) return ((-b + N)/(2*a), (-b - N)/(2*a)) but I stick with numpy, numpy is heavy, but not as much as using a computer to solve this problem ! And numpy should be standard module for computer science student ! Eric http://codeslash.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list