码迷,mamicode.com
首页 > 编程语言 > 详细

python 练习题

时间:2018-06-20 18:51:35      阅读:380      评论:0      收藏:0      [点我收藏+]

标签:一个   python 练习   csdn   math   计算   ==   接收   pow   https   

请定义一个函数quadratic(a, b, c),接收3个参数,返回一元二次方程:

ax2 + bx + c = 0

的两个解。

提示:计算平方根可以调用math.sqrt()函数

import math
def quadratic_equation(a, b, c):
t = math.sqrt(pow(b, 2) - 4 * a * c)
if(pow(b, 2) - 4 * a * c) > 0:
return (-b + t) / (2 * a), (-b - t) / (2 * a)
elif (pow(b, 2) - 4 * a * c) == 0:
return (-b + t) / (2 * a)
else:
return None
print quadratic_equation(4, 4, -8)

 

 

附一元二次方程推导

https://blog.csdn.net/hengbao4/article/details/73030664

python 练习题

标签:一个   python 练习   csdn   math   计算   ==   接收   pow   https   

原文地址:https://www.cnblogs.com/wushujun/p/9204673.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!