Created
May 8, 2016 07:58
-
-
Save complxalgorithm/96e1ac55373cec52ceadf1e9d694c909 to your computer and use it in GitHub Desktop.
Python program that takes three user input values and uses them to solve the quadratic equation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solve the quadratic equation ax**2 + bx + c = 0 | |
# Coeffients a, b and c are provided by the user | |
# import complex math module | |
import cmath | |
a = float(input('Enter a: ')) | |
b = float(input('Enter b: ')) | |
c = float(input('Enter c: ')) | |
# calculate the discriminant | |
d = (b**2) - (4*a*c) | |
# find two solutions | |
sol1 = (-b-cmath.sqrt(d))/(2*a) | |
sol2 = (-b+cmath.sqrt(d))/(2*a) | |
print('The solution are {0} and {1}'.format(sol1,sol2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment