Skip to content

Instantly share code, notes, and snippets.

@siddMahen
Created December 30, 2011 16:12
Show Gist options
  • Save siddMahen/1540452 to your computer and use it in GitHub Desktop.
Save siddMahen/1540452 to your computer and use it in GitHub Desktop.
Quadratic equation solver

Quadratic Equation Solver

Run this on the command line using python, takes the a, b and c values of the quadratic as arguments:

python quad.py 1 1 0

The above would solve for:

x^2 + x = 0

and output:

-1.0±√1.0
___________
2.0
# coding=UTF-8
import sys
import math
a = float(sys.argv[1]);
b = float(sys.argv[2]);
c = float(sys.argv[3]);
print str(-b)+"±√"+str(pow(b,2) - (4*a*c))+"\n___________\n"+str(2*a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment