Tanish69420

Quadratic equation---IIT DHOLAKPUR

Apr 23rd, 2022 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import math
  2.  
  3. g=input("Enter the quadratic equation ")
  4. g=g.split("+")
  5.  
  6. a1=str(g[0])
  7. a1=a1.split("x^2")
  8. if a1[0]=="":
  9.     a=1
  10. else:
  11.     a=int(a1[0])
  12. print(a)
  13.  
  14. b1=str(g[1])
  15. b1=b1.split("x")
  16. if b1[0]=="":
  17.     b=1
  18. else:
  19.     b=int(b1[0])
  20. print(b)
  21.  
  22. c1=str(g[2])
  23. c1=c1.split("x")
  24. if c1[0]=="":
  25.     c=0
  26. else:
  27.     c=int(c1[0])
  28. print(c)
  29.  
  30. d=b**2-4*a*c
  31. if d>=0:
  32.     x1=(-b+math.sqrt(d))/(2*a)
  33.     x2=(-b-math.sqrt(d))/(2*a)
  34.     print(x1,x2,"are the roots of the equation ")
  35. elif d<0:
  36.     d=-1*d
  37.     x1=(-b/(2*a))
  38.     x2=d/2*a
  39.     x3=complex(x1,x2)
  40.     x4=complex(x1,(-1*x2))
  41.     print(x3,x4,"are the roots of the equation ")
  42.  
  43.    
  44.    
  45.  
  46.  
Add Comment
Please, Sign In to add comment