Discuss / Python / 为什么算出来第一个的答案不对,第二个的正确?

为什么算出来第一个的答案不对,第二个的正确?

Topic source

单身旺2016

#1 Created at ... [Delete] [Delete and Lock User]

import math def quadratic(a, b, c): d = b b - 4 a c e = math.sqrt(d) x1 = (-b + e) / 2 a x2 = (-b - e) / 2 * a if a == 0: print('此方程无解!') else: return (x1, x2) print(quadratic(2, 3, 1)) print(quadratic(1, 3, -4))

答案为(-2.0, -4.0) (1.0, -4.0)

Android阳

#2 Created at ... [Delete] [Delete and Lock User]

2a带上小括号 (-b+e)/(2a)

Android阳

#3 Created at ... [Delete] [Delete and Lock User]
2*a带上小括号。 (-b+e)/(2*a)

  • 1

Reply