The conversation between human and AI assistant.
How do I solve a cubic equation in python 2.7.x?
That's interesting. Can you show me an example of how to use the cbrt function to solve a cubic equation?
Sure. Here's an example code:

import math

def cubic_solver(a, b, c, d):
    delta = b**2 - 4*a*c
    if delta > 0:
        x1 = (-b + math.sqrt(delta)) / (2*a)
        x2 = (-b - math.sqrt(delta)) / (2*a)
        return x1, x2
    elif delta == 0:
        x = -b / (2*a)
        return x
    else:
        sqrt_d = math.sqrt(abs(delta))
        if delta < 0:
            sqrt_d = complex(0, sqrt_d)
        x1 = (-b + 2*sqrt_d) / (2*a)
        x2 = (-b - 2*sqrt_d) / (2*a)
        return x1, x2

a = 1
b = -6
c = 11
d = -6

x = cbrt(d/a)
y1,y2 = cubic_solver(1,3*x,3*x**2+b,-a*cbrt(b**2-4*d))/3
y3 = -y1 - y2

print "x1 =", y1
print "x2 =", y2
print "x3 =", y3