输出错误:a float is required 怎么回事啊


xi=input().split()
a=float(xi[0]);b=float(xi[1]);c=float(xi[2])
d = b**2-4*a*c
g1=(-b + (b*b-4*a*c)**0.5)/(2*a)
g2=(-b - (b*b-4*a*c)**0.5)/(2*a)
x1 = format(g1,'.5f')
x2 = format(g2,'.5f')
if d==0:
    print('x1=x2=%g'%x2)


你的x1和x2已经是格式化后的字符串了,你的print却把它传给%g(浮点格式),这当然是不对的。%g改为%s输出字符串,或者print的最后一个x2改成g2。