p1_mrg_algebra2

2890 days ago by LAC2011

def disc(a,b,c): return b**2-4*a*c def real(a,b): return -b/(2*a) def imag(a,d): return sqrt(d)/(2*a) def root1(a,b,c): return real(a,b)+imag(a,disc(a,b,c)) def root2(a,b,c): return real(a,b)-imag(a,disc(a,b,c)) 
       
a=1 b=2 c=2 print a,"x**2 + ",b,"x + ",c," = 0" print "disc = ", disc(a,b,c) print "real = ", real(a,b) print "imag = ", imag(a,disc(a,b,c)) print "root1 = ", root1(a,b,c) print "root2 = ", root2(a,b,c) if disc(a,b,c)>=0: print "real" if sqrt(disc(a,b,c))==int(sqrt(disc(a,b,c))): print "rational" else: print "irrational" if disc(a,b,c)==0: print "equal roots!" else: print "unequal roots!!" else: print "complex conjugate roots!!!" 
       
1 x**2 +  2 x +  2  = 0
disc =  -4
real =  -1
imag =  I
root1 =  I - 1
root2 =  -I - 1
complex conjugate roots!!!
1 x**2 +  2 x +  2  = 0
disc =  -4
real =  -1
imag =  I
root1 =  I - 1
root2 =  -I - 1
complex conjugate roots!!!