Discuss / Python / a*x*x +b*x+c=0求解

a*x*x +b*x+c=0求解

Topic source
if not isinstance(a, (int, float)) or \   not isinstance(b, (int, float)) or \   not isinstance(c, (int, float)):    print("error args");    return;if (a == 0):    if (b == 0):        if (c == 0):            print("a=0,b=0,c=0恒等式");        else:            print("a=0,b=0,%f=0,恒不等式" % (c));    else:        print("只有一个解,x=", -c / b);else:    delta = b * b - 4 * a * c;    if (delta < 0):        print("del < 0,无解");    else:        x1 = (-b + math.sqrt(delta)) / (2 * a);        x2 = (-b - math.sqrt(delta)) / (2 * a);        print("x1=%f,x2=%f" % (x1, x2));

  • 1

Reply