Discuss / Python / 交作业

交作业

Topic source

pink

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

import math

def quadratic(a,b,c):

    #输入的得是数字吧

    if not (isinstance(a,(int,float)) 

    and isinstance(b,(int,float)) 

    and isinstance(c,(int,float))):

        return TypeError('输入数字!')

    #如果是一元一次?

    elif a == 0:

        x1 = -c/b

        return x1

    #根判定

    elif b**2-4*a*c < 0:

        return '无解!'

    else:

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

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

        return (x1,x2)


  • 1

Reply