python - incorrect answers for quadratic equations -


i wondering if tell me why python code solving quadratic equations isn't working. have looked through , haven't found errors.

print("this program solve quadratic equations you")  print("it uses system 'ax**2 + bx + c'")  print("a, b , c numbers or without decimal \ points")  print("firstly, value of a?")  = float(input("\n\ntype in coefficient of x squared"))  b = float(input("\n\nnow b. type in coefficient of x"))  c = float(input("\n\ngreat. c value? number alone?"))  print("the first value x " ,(-b+(((b**2)-(4*a* c))* * 0.5)/(2*a)))  print("\n\nthe second value x " ,(-b-(((b * * 2)-(4*a*c))** 0.5)/(2*a))) 

when a=1 b=-4 , c=-3 expecting -1 , 4 5.5 , 0.5

your trouble in part tries quadratic formula:

(-b+(((b**2)-(4*a* c))* * 0.5)/2*a) 

the trouble * has same precedence / you're dividing 2 , multiplying a. parentheses off, reduced unnecessary ones , moved wrong ones. in short, -b wasn't being put square root before division. want is:

(-b+(b**2-4*a*c)**0.5)/(2*a) 

p.s. sake of asking questions, better ask in form of like:

>>> = 2 >>> b = 1 >>> c = 3 >>> (-b+(((b**2)-(4*a* c))* * 0.5)/2*a) got blah, expected blam 

since other printing , inputting not blame (which should able work out easily).


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -