Discuss / Python / 解答

解答

Topic source

ddd

#1 Created at ... [Delete] [Delete and Lock User]
import mathdef quadratic(a, b, c):    for i in (a,b,c):        if not isinstance(i,(int,float)):            raise TypeError('bad operand type')    if b**2-4*a*c>=0:        x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)        x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)        return x1,x2    else:        raise TypeError('bad operand type')print(quadratic(2,3,1))print(quadratic(1,3,-4))

  • 1

Reply