我是python的新手,目前正在学习正确使用def函数.
我在Sublime Text中的def代码如下:
def quadratic(a,b,c):
if not isinstance(a,(int,float)):
raise TypeError('bad operand type')
if not isinstance(b,(int,float)):
raise TypeError('bad operand type')
if not isinstance(c,(int,float)):
raise TypeError('bad operand type')
d = b ** 2 - 4 * a * c
if d < 0:
print('no result!')
if d = 0:
x1 = -b / (2 * a)
x2 = x1
return x1,x2
else:
x1 = (-b + math.sqrt(d)) / (2 * a)
x2 = (-b - math.sqrt(d)) / (2 * a)
return x1,x2 …Run Code Online (Sandbox Code Playgroud)