python实现解一元二次方程

您所在的位置:网站首页 一元二次方程python程序 python实现解一元二次方程

python实现解一元二次方程

#python实现解一元二次方程| 来源: 网络整理| 查看: 265

python实现一元二次方程的求解

要考虑的点:

1、二元方程组a=0的情况

2、判别式是否大于0

3、当有复数解时如何表示

程序块:

# -*- coding: utf-8 -*- import math def root_of_square(a,b,c): '''solve the quadratic equation''' discr=pow(b,2)-4*a*c if a!=0 and discr>0: x1=(-b+math.sqrt(discr))/(2*a) x2=(-b-math.sqrt(discr))/(2*a) return x1,x2 elif a!=0 and discr==0: return -b/(2*a) elif a!=0 and discr


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3