大家帮我看看啊?谢谢
def quadratic(a, b, c): ... ping = bb-4ac ... if not isinstance(x, (int, float)): ... raise TypeError('bad operand type') ... if a == 0: ... x0=-c/b ... return x0 ... elif ping >0: ... x1=[-b+math.sqrt(ping)]/(2a) ... x2=[-b-math.sqrt(ping)]/(2a) ... return x1, x2 ... elif ping == 0: ... x3=-b/(2a) ... return x3 ... elif ping < 0: ... return"wujie" ...
print('quadratic(1, 3, -4) =', quadratic(1, 3, -4)) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 9, in quadratic TypeError: unsupported operand type(s) for /: 'list' and 'int'
我把方括号改过来之后就没问题了
Sign in to make a reply
_XHEENA
大家帮我看看啊?谢谢
def quadratic(a, b, c): ... ping = bb-4ac ... if not isinstance(x, (int, float)): ... raise TypeError('bad operand type') ... if a == 0: ... x0=-c/b ... return x0 ... elif ping >0: ... x1=[-b+math.sqrt(ping)]/(2a) ... x2=[-b-math.sqrt(ping)]/(2a) ... return x1, x2 ... elif ping == 0: ... x3=-b/(2a) ... return x3 ... elif ping < 0: ... return"wujie" ...