464,663 Members | 1,270 Online
Need help? Post your question and get tips & solutions from a community of 464,663 IT Pros & Developers. It's quick & easy.

# calculating the roots of ax**2+bx+c

 P: 3 hello : This is my code : ------------------------------------------ Expand|Select|Wrap|Line Numbers while True :     try:         ' enter the coefficients of the equation :'           a=input('a=' )         b=input('b=' )         c=input('c=' )           r=b**2-4*a*c         import cmath         sq=cmath.sqrt           if r==0 :             x=(-b)/(2*a)             y=(-b)/(2*a)             print 'the roots are :',x,',',y           elif r>0 :             x=((-b)+sq(r))/(2*a)             y=((-b)-sq(r))/(2*a)             print 'the roots are :',x,',',y           if r<-1 :             i=sq(-1)             x=(-b+(sq(r*(i**2))))/(2*a)             y=(-b-(sq(r*(i**2))))/(2*a)             print 'the roots are :',x,',',y     except :         print 'wrong inputs , please enter numbers only' ------------------ when r<-1 ################################################## ### ### the results are not like the casio calculater ### ################################################## ### Nov 27 '12 #1

#### ✓ answered by MR 010

I found it myself :)

i should use abs(r) :) , thanks for giving me a chance to ask you :)