python解一元二次方程步骤-使用Python解一元二次方程!

一元二次方程: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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值