Discuss / Python / 作业 感觉情形完整了

作业 感觉情形完整了

Topic source

import math

def quadratic(a,b,c):

    s = float (b**2 - 4*a*c)

    while a != 0:

        if s > 0:

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

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

            return x1,x2

        elif s == 0:

            x = (-b)/(2*a)

            return x

        else:

            return "无实数解"

    while a == 0:

        x = -c/b

        return x

a=float(input('请输入a值:'))

b=float(input('请输入b值:'))

c=float(input('请输入c值:'))

print('解为',quadratic(a,b,c))


  • 1

Reply