(在没有导入的二次方程中查找 x 的值。)每当我运行程序时,Python 都会停止discriminant = (b ** 2) - 4(a * c)
并显示 TypeError: 'int' object is not callable。怎么了?
#------SquareRootDefinition---------#
def Square_Root(n, x):
if n > 0:
y = (x + n/x) / 2
while x != y:
x = y
return Square_Root(n, x)
else:
if abs(10 ** -7) > abs(n - x ** 2):
return y
elif n == 0:
return 0
else:
return str(int(-n)) + "i"
#----------Quadratic Equation--------------#
a = input("Enter coefficient a: ")
while a == 0:
print "a must not be equal to 0."
a = input("Enter coefficient a: ")
b = input("Enter coefficient b: ")
c = input("Enter coefficient c: ")
def Quadratic(a, b, c):
discriminant = (b ** 2) - 4(a * c)
if discriminant < 0:
print "imaginary"
elif discriminant >= 0:
Sqrt_Disc = Square_Root(discriminant)
First_Root = (-b + Sqrt_Disc) / (2 * a)
Second_Root = (-b - Sqrt_Disc) / (2 * a)
return First_Root, Second_Root
X_1, X_2 = Quadratic(a, b, c)