def quadratic(a,b,c): if not isinstance(a,(int,float)): raise TypeError('bad oprand type') elif not isinstance(b,(int,float)): raise TypeError('bad oprand type') elif not isinstance(c,(int,float)): raise TypeError('bad oprand type') import math d=bb-4ac if a==0: if b==0: raise TypeError('bad operand type') else: return -(c/b) elif(d<0): return TypeError('bad oprand type') elif(d==0): return -b/(2a) else: x1 = (-b+math.sqrt(d))/(2a) x2 = (-b-math.sqrt(d))/(2a) return x1,x2
用“插入代码”
Sign in to make a reply
fridayily
def quadratic(a,b,c): if not isinstance(a,(int,float)): raise TypeError('bad oprand type') elif not isinstance(b,(int,float)): raise TypeError('bad oprand type') elif not isinstance(c,(int,float)):
raise TypeError('bad oprand type') import math d=bb-4ac if a==0: if b==0: raise TypeError('bad operand type') else: return -(c/b) elif(d<0): return TypeError('bad oprand type') elif(d==0): return -b/(2a) else: x1 = (-b+math.sqrt(d))/(2a) x2 = (-b-math.sqrt(d))/(2a) return x1,x2