题解 | #计算一元二次方程#

计算一元二次方程

http://www.nowcoder.com/practice/7da524bb452441b2af7e64545c38dc26

while 1:
    try:
        a , b ,c = map(float, input().split())
        if a == 0:
            print("Not quadratic equation")
        else:
            dela = (b **2) -(4 * a * c)
            if dela == 0:
                dela = (-b)/(2*a)+0
                print("x1=x2={:.2f}".format(dela))
            elif dela > 0 :
                dela1 = ((-b) +(dela ** 0.5) )/(2*a)
                dela2 = ((-b) - (dela ** 0.5) )/(2*a)
                print(f"x1={dela2:.2f};x2={dela1:.2f}")
            else:
                if b == 0:
                    a1 = 0
                    b1 = (dela**0.5)/(2*a)
                else:
                    a1 = (-b)/(2*a)
                    b1 = ((-dela)**0.5)/(2*a)
                if b1 < 0:
                    b1 = abs(b1)
                    print(f"x1={a1:.2f}-{b1:.2f}i;x2={a1:.2f}+{b1:.2f}i")
                else:
                    print(f"x1={a1:.2f}-{b1:.2f}i;x2={a1:.2f}+{b1:.2f}i")
    except:
            break

全部评论

相关推荐

10-28 15:45
门头沟学院 C++
西南山:海康威视之前不是大规模裁员吗
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务