Factoring Polynomials

James Mills prologic at shortcircuit.net.au
Fri Dec 19 01:41:37 CET 2008


On Fri, Dec 19, 2008 at 10:11 AM, Gabriel Genellina
<gagsl-py2 at yahoo.com.ar> wrote:
> En Thu, 18 Dec 2008 17:37:35 -0200, <collin.day.0 at gmail.com> escribió:
>
>> 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

Why is this so hard ? This is simple simple
expression. Reading through the Python
tutorial and reading up on how to define
functions is all you need! :)

Here goes:

>>> def f(a, b, c):
...     x = (-1 * b) + ((b**2 - (4 * a * c)) / (2 * a))
...     return (-1 * x), x
...
>>> f(1, 2, 3)
(6, -6)
>>>

cheers
James


More information about the Python-list mailing list