Let's say one of the answers is supposed to be 3.00
, it will be printed as 3.00+0.00j
.
How do I remove the j
and have it as 3.00
only?
# Viete's Algorithm
def result_2(a3,a2,a0,a1):
b = b_cof(a3,a2,a1,a0)
a = a_cof(a3,a2,a1)
p = P(a3, a2)
r = -(b / 2.0)
q = (a / 3.0)
if ((r**2)+(q**3))<= 0.0:
if q==0:
theta = 0
if q<0:
theta = cmath.acos(r/(-q**(3.0/2.0)))
phi1 = theta / 3.0
phi2 = phi1 - ((2*cmath.pi) / 3.0)
phi3 = phi1 + ((2*cmath.pi) / 3.0)
print("X1 = ", "{:.2f}".format(2*math.sqrt(-q)*cmath.cos(phi1)-p/3.0))
print("X2 = ", "{:.2f}".format(2*math.sqrt(-q)*cmath.cos(phi2)-p/3.0))
print("X3 = ", "{:.2f}".format(2*math.sqrt(-q)*cmath.cos(phi3)-p/3.0))