Factoring Polynomials

Terry Reedy tjreedy at udel.edu
Fri Dec 19 02:43:58 EST 2008


Collin D wrote:

> UPDATE:
> '
> 
> #import
> 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
> def solver(a,b,c):
>     if b**2 - 4*a*c < 0:
>         return 'No real solution.'
>     else:
>         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)
> 
> # execute
> print solver(a,b,c)

TEST your code.




More information about the Python-list mailing list