Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This program calculates possible solutions for a quadratic equation#
- #####################################################################
- # Introducing user with a quadratic equation
- print("Quadratic equation is any equation with the following form:\n\n\
- a * x * x + b * x + c = 0\n\n\
- where x is unknown while a, b and c are coefficients known as:\n\
- quadratic coefficient, linear coefficient and the constant, respectively.")
- print("\n")
- print("Note that quadratic coefficient cannot be 0. If a = 0 then the equation is linear, not quadratic.")
- print("\n")
- import math
- def equation_lower(quadratic, linear, constant):
- x = (-b - (math.sqrt(d))) / (2 * a)
- return x
- def equation_greater(quadratic, linear, constant):
- y = (-b + (math.sqrt(d))) / (2 * a)
- return y
- a = float(input("Enter quadratic coefficient: "))
- b = float(input("Enter linear coefficient: "))
- c = float(input("Enter constant coefficient: "))
- # Discriminant for calculating x
- d = b * b - 4 * a * c
- x_lower = equation_lower(a,b,c)
- x_greater = equation_greater(a,b,c)
- # Print the result
- print("Possible results are %f and %f" % (x_lower, x_greater))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement