BC73 计算一元二次方程
思路:
step1:按照要求输入输出;
代码如下:
while True:
try:
a,b,c = list(map(float,input().split()))
if int(a) == 0:
print('Not quadratic equation')
else:
delta = b**2 - (4*a*c)
if delta == 0:
print('x1=x2={:.2f}'.format(-b/(2*a)+0.00000000001))
elif delta > 0:
x1 = ((-b)+delta**0.5)/(2*a)
x2 = ((-b)-delta**0.5)/(2*a)
if x1 > x2:
x1,x2 = x2,x1
print('x1={:.2f};x2={:.2f}'.format(x1+0.000000001,x2+0.0000000001))
elif delta < 0:
m1 = (-b)/(2*a)
n1 = ((-(delta))**0.5)/(2*a)
if float(m1) == 0.00:
m1 = 0.00
if n1 >= 0:
print('x1={:.2f}-{:.2f}i;x2={:.2f}+{:.2f}i'.format(m1+0.000000001,n1+0.0000000001,m1+0.000000001,n1+0.0000000001))
else:
print('x1={:.2f}{:.2f}i;x2={:.2f}+{:.2f}i'.format(m1+0.000000001,n1+0.0000000001,m1+0.000000001,-(n1+0.0000000001)))
except:
break