Discuss / Python / 请指教

请指教

Topic source

import math

def quadratic(a , b , c):

    l = b ** 2 - 4*a*c

    if l <0:

        print('无解')

    elif l >0:

        x1 = (-b + math.sqrt(l))/2*a

        x2 = (-b - math.sqrt(l))/2*a

        print('此方程有两个根:%s,%s'%(x1,x2))

    else:

        x1 = (-b + math.sqrt(l))/2*a

        print('此方程只有一个根%s'%x1)


  • 1

Reply