0

Finding quadratic roots:

import math

def main(): 
    print "Hello! This program finds the real solutions to a quadratic"
    print

    a, b, c = input("Please enter the coefficients (a, b, c): ")

    d = (b**2) - (4*a*c) # finding the discriminant
    if d < 0:
        d = -d    
    else:
        print "This quadratic equation does not have imaginary roots"
        return

    dRoot = math.sqrt(d)

    root1r = (-b) / (2 * a)      
    root1i = dRoot / (2 * a)  

    root2r = root1r      
    root2i = -root1i     

    print "%s+%si , %s+%si" % (root1r, root1i, root2r, root2i)
    print

main()

sample::: a, b, c

0.0, 0.0, 0.0

0.0, 0.0, 1.0

0.0, 2.0, 4.0

1.0, 2.0, 1.0

1.0, -5.0, 6.0

1.0, 2.0, 3.0,

Need help making a quadratic equation that can help me find the square root(s) or outputing a message saying that the root cannot be found/ or it is undefinable. Using the given a, b, c as examples to finding root(s) or prompting a message. That is what i have,

  • Every quadratic equation has exactly two roots (in the complex plane). So there are no a, b, c such that the root cannot be found or is undefined. – Robert Dodier Jul 26 '16 at 18:53
  • I meant for instance when a=0 b=0 c=0, I would like for my result to output :"all values of x are solutions". – Jesus Anaya Jul 26 '16 at 23:00
  • I meant for instance when a=0 b=0 c=0, I would like for my result to output :"all values of x are solutions" and when a=0 b=0 c=1 I would like for my output to "no solutions exist" – Jesus Anaya Jul 26 '16 at 23:14

0 Answers0