Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. module: quardic-equation-anshih.py
  2.  
  3. from quardic import calculateQuardic
  4.  
  5. calculateQuardic(2,4,6)
  6. -------------------------------------------
  7.  
  8.  
  9. quardic.py
  10.  
  11. import cmath
  12. # function to check for
  13. # solutions of equations
  14. def calculateQuardic(a, b, c):
  15. if (a == 0):
  16. print('Value of a cant be 0')
  17. return ()
  18. d = b ** 2 - 4 * a * c # discriminant
  19.  
  20. if d < 0:
  21. print("This equation has no real solution")
  22. elif d == 0:
  23. x = (-b + cmath.sqrt(b ** 2 - 4 * a * c)) / 2 * a
  24. print("This equation has one solutions: "), x
  25. else:
  26. x1 = (-b + cmath.sqrt((b ** 2) - (4 * (a * c)))) / (2 * a)
  27. x2 = (-b - cmath.sqrt((b ** 2) - (4 * (a * c)))) / (2 * a)
  28. print("This equation has two solutions: ", x1, " or", x2)
  29.  
  30. if __name__ == "__main__":
  31. a, b, c = -2, 4, 3
  32. calculateQuardic(a, b, c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement