#!/usr/bin/env python print("Quadratic Equation Solver, Enter a, b, and c below:\n") print("Enter three comma separated numbers a, b, c ") myInput = input() # Separate on comma. terms = myInput.split(",") # Loop and print each city name. #for term in terms: # print(term) print terms[0],"x^2 + ",terms[1],"x + ", terms[2]," = 0 is solved as:" a = float(terms[0]) b = float(terms[1]) c = float(terms[2]) discriminant = b*b - 4*a*c x = -b y = -b if discriminant > 0: x = x + math.sqrt(discriminant) y = y - math.sqrt(discriminant) elif discriminant < 0: x = -999 #temporary y = -999 print "x_1 = ",x/2/a,"x_2 =", y/2/a
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question