Discuss / Python / 多看评论才是王道

多看评论才是王道

Topic source

Sir__Humphrey

#1 Created at ... [Delete] [Delete and Lock User]
import math
def quadratic(a, b, c):
    if a!=0:
        if b**2-4*a*c>=0:
            if b**2 - 4*a*c==0:
                x=-b/2*a
                return x
            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
        else:
            x1=(-b+math.sqrt(4*a*c-b**2))/2*a
            x2=(-b-math.sqrt(4*a*c-b**2))/2*a 
            return x1,x2
    else:
        if b==0:
            return none
        else:
            x=-c/b
            return x
a = int(input("please input number a:"))     
b= int(input("please input number b:")) 
c= int(input("please input number c:"))   
print(quadratic(a,b,c))

  • 1

Reply