Discuss / Python / 不足之处:1.没有考虑a=0的情况 2.没有对输入的数据进行检查

不足之处:1.没有考虑a=0的情况 2.没有对输入的数据进行检查

Topic source
import math
def quadratic(a, b, c):
        temp=b*b-4*a*c
        if temp==0:
            return (-b)/2/a
        elif temp>0:
            x1=(-b-math.sqrt(temp))/(2*a)
            x2=(-b+math.sqrt(temp))/(2*a)
            return (x1 ,x2)
        else:
            return ("无实数解")
a=int(input('Please enter the parameter a:'))
b=int(input('Please enter the parameter b:'))
c=int(input('Please enter the parameter c:'))
print (quadratic(a,b,c))

  • 1

Reply