croots() was written by Tim Peters def croots(c, n): """Return list of the n n'th roots of complex c.""" from math import sin, cos, atan2, pi arg = abs(c)**(1.0/n) theta = atan2(c.imag, c.real) result = [] for i in range(n): theta2 = (theta + 2*pi*i)/n x = arg * cos(theta2) y = arg * sin(theta2) result.append(complex(x, y)) return result