Discuss / Python / 这个作业太难了呜呜呜

这个作业太难了呜呜呜

Topic source

import math

def quadratic(a,b,c):

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

            raise TypeError (' 请输入整数或浮点数 ' )

    if not isinstance(b, (int, float)):

            raise TypeError (' 请输入整数或浮点数 ' )

    if not isinstance(c, (int,float)):

            raise TypeError (' 请输入整数或浮点数 ' )

    if a==0:

            return'一元一次方程组'

    else:

     h = b**2-4*a*c

    if h>=0:

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

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

         return x1,x2 

    else:

         return ' 无解 '

学习了,点赞


  • 1

Reply