Discuss / Python / my code

my code

Topic source

levonsoft

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

import math

def quadratic(a,b,c):

    if (a==0):

        return False,"param a invalid!"

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

    if (xx < 0):

        return False, "no answer"

xx=math.sqrt(xx)

    y1=(-b+xx)/(2*a)

    y2=(-b-xx)/(2*a)

    return True,y1,y2

#test code:
tupleA=(quadratic(2,8,6))

if (tupleA[0]==False):

    print("calc error,error reason:", tupleA[1])

else:

    print("calc suc,the answer is: %f, %f" % (tupleA[1],tupleA[2]))


  • 1

Reply