Discuss / Python / 求指导,哪里不对

求指导,哪里不对

Topic source

-- coding: utf-8 --

import math

def quadratic(a, b, c): d1 = 2a d2 = bb-4ac d3 = math.sqrt(d2)

if a>0:
    if d2<0:
        print('There is none root.')
    elif d2 == 0:
        x = -b/(d1)
        print('There exists only one root:',x)
    else:
        x1 = (-b+d3)/d1
        x2 = (-b-d3)/d1
        print('There exists two roots:',x1,x2)
else:
    print('The denominator can not be less than zero.')

print(quadratic(2, 3, 1))

补充:结果是这样

Result

There exists two roots: -0.5 -1.0 None There exists two roots: -0.5 -1.0 None There exists two roots: 1.0 -4.0 None


  • 1

Reply