L = (a,b,c)
for x in L:
if not isinstance(x,(int,float)):
raise TypeError('bad operand type')
检查是否存在解
if b * b - 4 * a * c < 0:
print('no solution','\n')
求解
elif b * b - 4 * a * c == 0:
print('This equation has only one solution:','\n',(math.sqrt(b*b-4*a*c)-b)/(2*a),'\n')
else:
print('This equation has two solutions:','\n')
print('x1 = ',(-b+math.sqrt(b*b-4*a*c))/(2*a),'\n'+'x2 = ',(-b-math.sqrt(b*b-4*a*c))/(2*a),'\n')
勤奋蘑菇仔
参数检查
检查是否存在解
求解