Skip to content

Instantly share code, notes, and snippets.

@complxalgorithm
Created May 8, 2016 07:58
Show Gist options
  • Save complxalgorithm/96e1ac55373cec52ceadf1e9d694c909 to your computer and use it in GitHub Desktop.
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.
# 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