import mathimport cmathdef qudratic(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") delta = cmath.sqrt(b**2-4*a*c) if abs(delta) != delta: print("此方程无实数解,但有以下虚数解:") else: delta = math.sqrt(b ** 2 - 4 * a * c) print("此方程有实数解如下:") x_01 = (-b + delta)/(2*a) x_02 = (-b - delta)/(2*a) d = {} d.fromkeys(("x1","x2")) d["x1"] = x_01 d["x2"] = x_02 l_01 = d.items() print(d) print(l_01) return x_01,x_02,l_01x = qudratic(10,-13,10)
Sign in to make a reply
緣定さんせぃ様