Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- g=input("Enter the quadratic equation ")
- g=g.split("+")
- a1=str(g[0])
- a1=a1.split("x^2")
- if a1[0]=="":
- a=1
- else:
- a=int(a1[0])
- print(a)
- b1=str(g[1])
- b1=b1.split("x")
- if b1[0]=="":
- b=1
- else:
- b=int(b1[0])
- print(b)
- c1=str(g[2])
- c1=c1.split("x")
- if c1[0]=="":
- c=0
- else:
- c=int(c1[0])
- print(c)
- d=b**2-4*a*c
- if d>=0:
- x1=(-b+math.sqrt(d))/(2*a)
- x2=(-b-math.sqrt(d))/(2*a)
- print(x1,x2,"are the roots of the equation ")
- elif d<0:
- d=-1*d
- x1=(-b/(2*a))
- x2=d/2*a
- x3=complex(x1,x2)
- x4=complex(x1,(-1*x2))
- print(x3,x4,"are the roots of the equation ")
Add Comment
Please, Sign In to add comment