二次方程计算器和我使用的代码无法正常工作。代码上有一些错误。
我已经尝试过使用基本数字,例如1/2/3。没有方程式。代码仍然不起作用。真正起作用的是仅放置变量,仅此而已。按Enter键查看答案后,它说我的代码有一些错误。
print ("Quadratic Equation Calculator")
import math
print ("Enter the first variable : ")
first = float(input(''))
print ("Enter the second variable : ")
second = float(input(''))
print ("Enter the third variable : ")
third = float(input(''))
Answer1 = ((-1 * second) - math.sqrt((math.pow(second, 2) - 4.0*first*third))) / (2*first)
Answer2 = ((-1 * second) + math.sqrt((math.pow(second, 2) - 4.0*first*third))) / (2*first)
print (Answer1)
print (Answer2)
我希望正确回答问题,并且该方程计算器可用于实方程和变量。 x平方和3x等。
似乎您正在寻找二次函数 取决于y = a*x^2 + b*x + c
的根。取决于a
,b
和c
的值。 (请注意,由于这些变量是常用的数学名称,因此应使用这些变量名而不是first
,second
和third
。])a
,b
和c
的值,根可能是复数。我建议您从一些[
print ("Quadratic Equation Calculator")
import math
print ("Enter the first variable : ")
a1= float(input(''))
print ("Enter the second variable : ")
b1= float(input(''))
print ("Enter the third variable : ")
c1= float(input(''))
Answer1=((-1*b1)+math.sqrt((b1**2)-(4*a1*c1)))/(2*a1)
Answer2=((-1*b1)-math.sqrt((b1**2)-(4*a1*c1)))/(2*a1)