一元二次方程:ax² + bx + c = 0
求根公式:x = (-b+√(b²-4ac))/2a
判别式:b²-4ac
def my_math(a, b , c):
if not isinstance(a,(int, float)) and not isinstance(b, (int, float)) and not isinstance(c, (int, float)) :
raise TypeError(\"输入的参数类型有误\" + a)
# elif not isinstance(b, (int, float)):
# raise TypeError(\"输入的参数类型有误\" + b)
# elif not isinstance(c, (int, float)):
# raise TypeError(\"输入的参数类型有误\" + c)
else:
dist = pow(b,2) - (4 * a * c)
print(dist)
if dist == 0:
result = -b / (2 * a)
print(\"只有一个相同的实数:\", result)
if dist < 0:
print(\"没有实数\")
if dist > 0:
result1 = (-b + math.sqrt(dist)) /2 * a
result2 = (-b - math.sqrt(dist)) / 2 * a
print(result1)
print(result2)
my_math(-6,6,6)
继续阅读与本文标签相同的文章
-
阿里云开发者社区问答栏目提问规范
2026-05-18栏目: 教程
-
小伙上演“无人驾驶”手舞足蹈,女网友拍视频发朋友圈结果“悲剧了”……
2026-05-18栏目: 教程
-
迎来“无后门协议”!持续压制无效?5G建设选择在于技术问题
2026-05-18栏目: 教程
-
Pepper Metrics - Spring/Spring Boot应用性能监控利器
2026-05-18栏目: 教程
-
ZKEYS:数字化时代,IDC云化解决方案的探索实践
2026-05-18栏目: 教程
