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,
Aucun commentaire:
Enregistrer un commentaire