Discuss / Python / 刚开始我竟然把2a理解成了2*a,看来程序和数学还是有区别哈哈

刚开始我竟然把2a理解成了2*a,看来程序和数学还是有区别哈哈

Topic source

青年小哲

#1 Created at ... [Delete] [Delete and Lock User]
def answer(a,b,c):

    delta = b**2 - (4*a*c)
    if delta < 0:
        print('Because delta is negative, This Quadratic equation have no real roots.')
        print('But it has two distinct (non-real) complex roots.')
        return 'No real roots'
    elif delta == 0:
        x = (-b)/2*a
        print('The only root for this Quadratic equation is %.3f' % x)
        return x
    else:
        x_1 = (-b+(math.sqrt(delta)))/(2*a)
        x_2 = (-b-(math.sqrt(delta)))/(2*a)
        print('The two different roots is %.3f and %.3f' % (x_1, x_2))
        return x_1, x_2


  • 1

Reply