在python上需要有关二次公式的帮助

时间:2016-10-11 21:05:04

标签: python math formula quadratic

我刚开始在学校学习Python,这是我的二次公式求解器的代码。问题在第4行。

a=int(input('a= ')) # A-stvis mnishvnelobis micema
b=int(input('b= ')) # B-stvis mnishvnelobis micema
c=int(input('c= ')) # C-stvis mnishvenlobis micema
int(a)*(x2)+int(b)*x+c=0
d=(-b2)-4*a*c
x1=-b+(d**(1/2))
x2=-b-(d**(1/2))

1 个答案:

答案 0 :(得分:1)

from math import sqrt

a = int(input('a= ')) # A-stvis mnishvnelobis micema
b = int(input('b= ')) # B-stvis mnishvnelobis micema
c = int(input('c= ')) # C-stvis mnishvenlobis micema
d = b**2 - 4*a*c
x1 = (-b - sqrt(d))/2
x2 = (-b + sqrt(d))/2

print("x1 =", x1)
print("x2 =", x2)

不需要你的等式,python也不理解它。如果你愿意,你可以发表评论。

尝试使用平方根(sqrt)而不是取幂(**