Discuss / Python / 重新敲了一遍可以了,然而我还是不知道之前为啥报错

重新敲了一遍可以了,然而我还是不知道之前为啥报错

Topic source

清寒藏韵

#1 Created at ... [Delete] [Delete and Lock User]

# -*- coding:utf-8 -*-

def quadratic(a,b,c):

    if b**2-4*a*c < 0:

        return'该方程无解'

    elif b**2-4*a*c == 0:

        x = -b/(2*a)

        return('该方程有且仅有一个解,即%6.3f'%x)

    else:

        x = (-b+math.sqrt(b**2-4*a*c))/(2*a)

        y = (-b-math.sqrt(b**2-4*a*c))/(2*a)

        return('该方程有两个解,分别是%6.3f和%6.3f'%(x,y))


  • 1

Reply