Discuss / Python / 求指点

求指点

Topic source

孤音

#1 Created at ... [Delete] [Delete and Lock User]

import math

def quadratic(a,b,c):

    if not isinstance(a,(int, float)) or not isinstance(b,(int,float)) or not isinstance(c,(int,float)):

        raise TypeError('bad operand type')

    if b*b-4*a*c >= 0:

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

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

      return x1, x2

    else:

       print('无解')


  • 1

Reply