Chap 2- Ex 4: find all the roots of ax2+bx+c=0
unknown
plain_text
3 years ago
589 B
9
Indexable
import math
a=int(input("a="))
b=int(input("b="))
c=int(input("c="))
if a==0:
# TODO: b=0 (c=0, c!=0)
if b==0:
if c!=0:
print("FALSE")
else:
print("FALSE")
else:
x=-c/b
print("the value of x is", x)
elif a!=0:
denta= b*2-4*a*c
if denta>0:
x1 = (-b-math.sqrt(denta))/2/a
x2 = (-b+math.sqrt(denta))/2/a
print("the values of x are", x1, "and", x2)
elif denta<0:
print("FALSE")
else:
x = -b/2/a
print("the values of x is", x)Editor is loading...