Discuss / Python / 交作业

交作业

Topic source

xinyujaychou

#1 Created at ... [Delete] [Delete and Lock User]

#练习 ax2 + bx + c = 0 的解

def quadratic(a, b, c): delta = pow(b, 2) - 4 a c if delta < 0 : print('方程无解') else : sqrtDelta = math.sqrt(delta) x1 = (-b + sqrtDelta) / 2 a x2 = (b + sqrtDelta) / 2 a return (x1, x2)

print('欢迎使用一元二次方程ax^2+bx+c=0求根函数') a = float(input('a = ')) b = float(input('b = ')) c = float(input('c = ')) result = quadratic(a,b,c) if result is not None : print('解为x1 = %f, x2 = %f' %(result))


  • 1

Reply