Advertisement
Toma252

4.3 quadratic equation 1

Oct 16th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. #This program calculates possible solutions for a quadratic equation#
  2. #####################################################################
  3.  
  4. # Introducing user with a quadratic equation
  5. print("Quadratic equation is any equation with the following form:\n\n\
  6. a * x * x + b * x + c = 0\n\n\
  7. where x is unknown while a, b and c are coefficients known as:\n\
  8. quadratic coefficient, linear coefficient and the constant, respectively.")
  9. print("\n")
  10. print("Note that quadratic coefficient cannot be 0. If a = 0 then the equation is linear, not quadratic.")
  11. print("\n")
  12.  
  13. import math
  14.  
  15. def equation_lower(quadratic, linear, constant):
  16.     x = (-b - (math.sqrt(d))) / (2 * a)
  17.     return x
  18.  
  19. def equation_greater(quadratic, linear, constant):
  20.     y = (-b + (math.sqrt(d))) / (2 * a)
  21.     return y
  22.    
  23. a = float(input("Enter quadratic coefficient: "))
  24. b = float(input("Enter linear coefficient: "))
  25. c = float(input("Enter constant coefficient: "))
  26.  
  27. # Discriminant for calculating x
  28. d = b * b - 4 * a * c
  29.  
  30. x_lower = equation_lower(a,b,c)
  31. x_greater = equation_greater(a,b,c)
  32.  
  33.  
  34. # Print the result
  35. print("Possible results are %f and %f" % (x_lower, x_greater))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement