a, b, c, d = map(float, input().split())
def calEq(x):
return a * x * x * x + b * x * x + c * x + d
# print(f"Input values: a={a}, b={b}, c={c}, d={d}")
ans = [0.00] * 3
loation = 0
for i in range(-100, 101):
left = i
right = i + 1
# 左端点是根
if calEq(left) == 0:
ans[loation] = left
loation += 1
# print("{:.2f}".format(left), end=' ')
if calEq(left) * calEq(right) < 0:
while right - left > 1e-3:
mid = (left + right) / 2
if calEq(mid) * calEq(right) > 0:
right = mid
else:
left = mid
ans[loation] = right
loation += 1
for i in range(len(ans)):
if i < len(ans) - 1:
print("{:.2f}".format(ans[i]), end=' ')
else:
print("{:.2f}".format(ans[i]))
一开始用if elif,把right符合条件的跳过,出现问题,之后改用全if就AC了
6101

被折叠的 条评论
为什么被折叠?



