collin.day.0 at gmail.com
Fri Dec 19 02:37:40 CET 2008
On Dec 18, 5:30 pm, "James Mills" <prolo... at shortcircuit.net.au>
> jmills at atomant:~/tmp$ cat polycalc.py
> #!/usr/bin/env python
> from math import sqrt
> def f(a, b, c):
> if (b**2 - (4 * a * c)) < 0:
> return None, None # Can't solve
> x1 = -b - (sqrt(b**2 - (4 * a * c)) / (2 * a))
> x2 = -b + (sqrt(b**2 - (4 * a * c)) / (2 * a))
> return x1, x2
> print "Polynomial Solver..."
> while True:
> a = float(raw_input("a: "))
> b = float(raw_input("b: "))
> c = float(raw_input("c: "))
> x = f(a, b, c)
> if None in x:
> print "Can't solve!"
> print "x = (%0.2f, %0.2f)" % x
> jmills at atomant:~/tmp$ ./polycalc.py
> Polynomial Solver...
> a: 1
> b: 8
> c: 5
> x = (-11.32, -4.68)
Ahh. Great.. that answers a lot of questions.
Originally I was using just a = raw_input('a: ')
And was getting errors because you cant perform mathmatical operations
on strings. >.<
More information about the Python-list