Discuss / Python / 练习作业

练习作业

Topic source

小燕儿cy

#1 Created at ... [Delete] [Delete and Lock User]
 def quadratic(a, b, c):
    if not isinstance(a, (int, float)):
        raise TypeError('bad operand type')
    if not isinstance(b, (int, float)):
        raise TypeError('bad operand type')
    if not isinstance(c, (int, float)):
        raise TypeError('bad operand type')
    y=b**2-4*a*c
    s=math.sqrt(y)
    print(s)
    if s<0:
        return '此方程无解'
    elif s==0:
        return -b/(2*a)
    else:
        return (-b+s)/(2*a) ,(-b-s)/(2*a)

  • 1

Reply