fork download
  1. import math
  2.  
  3. def rootsQEq():
  4. print("This program finds the real solutions to a quadratic.")
  5. print()
  6.  
  7. a=0
  8. b=3
  9. c=2
  10.  
  11. discriminant = b * b - 4 * a * c
  12. if a == 0:
  13. print("Cannot divide by zero")
  14. elif discriminant < 0:
  15. print("The equation has no real roots!")
  16. elif discriminant == 0:
  17. root = -b/(2*a)
  18. print("\nThere is a double root at", root)
  19. else:
  20. s_root_val = math.sqrt(discriminant)
  21. root1 = (-b + s_root_val)/(2*a)
  22. root2 = (-b - s_root_val)/(2*a)
  23. print("\nThe solutions are: ", root1, root2)
  24. rootsQEq()
  25.  
  26.  
Success #stdin #stdout 0.08s 14172KB
stdin
Standard input is empty
stdout
This program finds the real solutions to a quadratic.

Cannot divide by zero