for num in [a,b,c]:
if not isinstance(num,(int,float)):
raise TypeError('bad operand type')
delta = b**2-4*a*c
if delta < 0:
print('没有实根')
else:
delta1 = math.sqrt(delta)
x1 = ((-b)+delta1)/(2*a)
x2 = ((-b)-delta1)/(2*a)
return x1, x2
Sign in to make a reply
MajorTomi
for num in [a,b,c]:
if not isinstance(num,(int,float)):
raise TypeError('bad operand type')
delta = b**2-4*a*c
if delta < 0:
print('没有实根')
else:
delta1 = math.sqrt(delta)
x1 = ((-b)+delta1)/(2*a)
x2 = ((-b)-delta1)/(2*a)
return x1, x2