単純な線形および二次方程式の計算に問題があります。二次は機能しますが、線形は機能しません。浮動小数点数で答えが得られますが、何らかの理由で常に数値と 0 になります。たとえば、2x + 13 = 0を解きたい場合、答えは-7.0になりますが、 -6.5である必要があります。なんらかの理由で(天井を)切り上げると思います。どこかに構文エラーがあると確信していますが、それを見つけることができません。この問題を解決する方法について何か提案はありますか? ご協力いただきありがとうございます。
import math
a,b,c = input("Enter the coefficients of a, b and c separated by commas: ")
d = b**2-4*a*c # discriminant
if a == 0:
x = -c/b # liner equation
x = float(x)
b = float(b)
c = float(c)
print "This linear equation has one solution:", x
elif d < 0:
print "This quadratic equation has no real solution"
elif d == 0:
x = (-b+math.sqrt(d))/(2*a)
print "This quadratic equation has one solutions:", x
else:
x1 = (-b+math.sqrt(d))/(2*a)
x2 = (-b-math.sqrt(d))/(2*a)
print "This quadratic equation has two solutions:", x1, "and", x2