faqts : Computers : Programming : Languages : Python

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 3 people (100%) answered Yes
Recently 3 of 3 people (100%) answered Yes

Entry

I have been writing a program for quadratic formula and I don't know how to write square roots

May 10th, 2006 14:04
stephen brown, Ben Crane,


The square root function is in the math module:
>>> from math import sqrt
>>> sqrt(3)
1.7320508075688772
>>> 
There's a version in the complex math module that
will handle complex roots:
>>> from cmath import sqrt
>>> sqrt(-3)
1.7320508075688772j
>>> 
You may find the complex version useful, but if you
want both branches of the root, you'll still have to
do some checking.