#solve for the equations specifically quadratict! import math def solve_quadratic_equation(a,b,c):#a,b,c are the equations parameters if a==0: print "This isn't a quadratict equation!" else: alfa=b**2-4*a*c if alfa> 0: x1=(-b-math.sqrt(alfa))/(2*a) x2=(-b+math.sqrt(alfa))/(2*a) print "The fisrt solution of the equation is",x1 print "The second solution of the equation is",x2 elif alfa==0: x=(-b)/(2*a) print "The solution for this equation is", x else:#if alfa <0 print "There is no solution for this equation" ############################################################################################################################# #lest solve the equation x**2+2*x+1=0 solve_quadratic_equation(1,2,1) print (-1)**2+2*(-1)+1 #lest solve the equation x**4+6*x+11=0 solve_quadratic_equation(1,4,11) print (-1)**4+6*(-1)+11
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