二次方程求解

来源:互联网 发布:电子商务一级域名 编辑:程序博客网 时间:2024/05/17 21:16
import mathdef  main():    print ("let us find the solution to a quadratic\n")    a, b, c=eval(input("please input the coefficients(a,b,c):"))    delta=b*b-4*a*c    if a==0:        x=-b/c        print("\nthere is a solution ",x)    elif delta<0:        print ("\n the solution has no real roots!")    elif delta==0:        x=-b/(2*a)        print ("there is a double root at",x)    else :        delta=math.sqrt(delta)        root1=(-b+delta)/(2*a)        root2=(-b-delta)/(2*a)        print ("\nThe solution are:", root1,root2)main()

0 0
原创粉丝点击