Discuss / Python / zuoye

zuoye

Topic source

腾腾2318

#1 Created at ... [Delete] [Delete and Lock User]

def quadratic(a, b, c): if not isinstance(a, (int, float)): raise TypeError("bad operand typr") if not isinstance(b, (int, float)): raise TypeError("bad operand typr") if not isinstance(c, (int, float)): raise TypeError("bad operand typr") sqrtt = math.sqrt(bb - 4 a c) if (sqrtt < 0): return None ans1 = (-1 b + sqrtt) / (2 a) ans2 = (-1 b - sqrtt) / (2 * a) return (ans1,ans2)

完全不需要三个 raise TypeError("bad operand typr")吧,把三个判断合并一下就行。


  • 1

Reply