解题思路:
见代码
参考代码:
def x0(a,b,c): s = b**2-4*a*c if s > 0: x1 = -b+(s)**(1/2)/(2*a) x2 = -b-(s)**(1/2)/(2*a) print('x1={:.3f} x2={:.3f}'.format(x1,x2)) elif s == 0: x1=x2=-b/2*a print('x1={:.3f} x2={:.3f}'.format(x1,x2)) elif s < 0: l = ((s**(1/2))/(2*a)).imag #取出a+bj中b的值 print('x1={0:.3f}+{1:.3f}i x2={0:.3f}-{1:.3f}i'.format(-b/(2*a),l)) a,b,c = input().split() a,b,c = int(a),int(b),int(c) x0(a,b,c)
0.0分
0 人评分