import math def roots1(outfile,a,b,c): r1 = "%f*x^2 + %f*x + %f == 0 \ninfinite roots."%(a,b,c) outfile.write(r1) def roots2(outfile, a,b,c): r2 = "%f*x^2 = %f*x + %f = 0\nhas no roots."%(a,b,c) outfile.write(r2) def roots3(outfile, a,b,c): y = -c/b r3 = "%f*x^2 + %f*x +%f = 0\nhas one root: x =%f"%(a,b,c,y) outfile.write(r3) def roots4(outfile,a,b,c,d): y = (-b)/(2*a) r4 = "%f*x^2 + %f*x + %f = 0\nd = %f\nhas two real roots:\nx1 = %f"%(a,b,c,d,y) outfile.write(r4) def roots5(outfile,a,b,c): x1 = ((-b) + math.sqrt(d))/(2*a) x2 = ((-b) - math.sqrt(d))/(2*a) x1 = float(x1) x2 = float(x2) r5 = "%f*x^2 + %f*x + %f = 0\nd = %f\nhas two real roots:\nx1 = %rf\nx2 = %f"%(a,b,c,d,x1,x2) outfile.write(r5) def roots6(outfile,a,b,c): d = -d x1r = (-b)/(2*a) x1i = math.sqrt(d)/(2*a) x2r = x1r x2i = -xli r6 = "%f*x^2 = %f*x + %f = 0\nd = %f\ntwo complex roots:\nx1 = % f + i * %f\nx2 = %f + i *%f\n"%(a,b,c,d, x1r, x1i, x2r, x2i) outfile.write(r6)
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