已知一元二次方程的3个参数a,b,c,编写python程序求方程实根
1个回答
展开全部
import math
a = float(raw_input('Enter coefficient a'))
b = float(raw_input('Enter coefficient b'))
c = float(raw_input('Enter coeeficient c'))
if a == 0:
s = -c/b
print 's:', s
else:
delta = b ** 2 - 4 * a *c
if delta < 0:
print 'No solution'
elif delta == 0:
s = -b/(2 * a)
print 's:', s
else:
root = math.sqrt(delta)
s1 = (-b + root) / (2 * a)
s2 = (-b - root) / (2 * a)
print 'Two distinct solution are', s1, s1
a = float(raw_input('Enter coefficient a'))
b = float(raw_input('Enter coefficient b'))
c = float(raw_input('Enter coeeficient c'))
if a == 0:
s = -c/b
print 's:', s
else:
delta = b ** 2 - 4 * a *c
if delta < 0:
print 'No solution'
elif delta == 0:
s = -b/(2 * a)
print 's:', s
else:
root = math.sqrt(delta)
s1 = (-b + root) / (2 * a)
s2 = (-b - root) / (2 * a)
print 'Two distinct solution are', s1, s1
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |