定义函数返回 ax2 + bx + c = 0的两个解

mac2022-06-30  139

# -*- coding: utf-8 -*- import math def quadratic(a, b, c): s = b*b - 4*a*c if a == 0: x = -c / b return x elif s==0: x = -b / 2*a return x elif s < 0: return 'no anwser' else: x = (-b + math.sqrt(s)) / (2 * a) y = (-b - math.sqrt(s)) / (2 * a) return x, y

转载于:https://www.cnblogs.com/fanren224/p/8457304.html

最新回复(0)