Python姹備竴鍏冧簩娆℃柟绋嬭В,,鏍囩锛?a hre
Python姹備竴鍏冧簩娆℃柟绋嬭В,,鏍囩锛?a hre
鏍囩锛?a href='http://www.byrx.net/so/1/sqrt' title='sqrt'>sqrt
棰樼洰锛?
璇峰畾涔変竴涓嚱鏁?鈥檘uadratic(a,b,c)鈥橈紝鎺ユ敹涓変釜鍙傛暟锛岃繑鍥炰竴鍏冧簩娆℃柟绋?
ax2 + bx + c = 0
鐨勪袱涓В銆傦紙鎻愮ず锛氳绠楀钩鏂规牴鍙互璋冪敤math.sqrt()鍑芥暟锛?/p>
import mathdef quadratic(a, b, c): if not isinstance(a, (int, float)): raise TypeError(鈥榓 is not a number鈥? if not isinstance(b, (int, float)): raise TypeErrot(鈥榖 is not a number鈥? if not isinstance(c, (int, float)): raise TypeError(鈥榗 is not a number鈥? derta = b * b - 4 * a * c if a == 0: if b == 0: if c == 0: return 鈥樻柟绋嬫牴鏄叏浣撳疄鏁扳€? else: return 鈥樻柟绋嬫棤鏍光€? else: x1 = -c / b x2 = x1 return x1, x2 else: if derta < 0: return 鈥樻柟绋嬫棤鏍光€? else: x1 = (-b + math.sqrt(derta)) / (2 * a) x2 = (-b - math.sqrt(derta)) / (2 * a) return x1, x2print(quadratic(2, 3, 1))print(quadratic(1, 3, -4))
銆€銆€
Python姹備竴鍏冧簩娆℃柟绋嬭В
鏍囩锛?a href='http://www.byrx.net/so/1/sqrt' title='sqrt'>sqrt
鍘熸枃鍦板潃锛歨ttps://www.cnblogs.com/sisul/p/8407334.html
评论关闭