Discuss / Python / 交作业

交作业

Topic source

Mr_7ian

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

# -*- coding: utf-8 -*-

import math

def quadratic(a,b,c):

    if a == 0:

        if b == 0:

            if c == 0:

                return 'x有任意解'

            else:

                return 'x无解'

        else:

            x = -c/b   

            return x

    else:

        if b**2 < 4*a*c:

            return 'x无实数解'

        if b**2 == 4*a*c:

            x = -b/(2*a)

            return x

        else:

            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

print(quadratic(-1,2,3)) #修改参数以测试


  • 1

Reply