使用IDE为PyCharm
首先是添加numpy包操作如下
第一步 File ->settings 第二步 project ->project interpreter 再点击右边+ 第三步 第四步 等待安装完毕即可说明
numpy的sqrt可以对正负数进行开方 ,可以处理ax^2+bx+c=0的所有情况,即sqrt 对实数、复数统一处理
实现代码如下from numpy.lib.scimath import sqrt a = int(input()) b = int(input()) c = int(input()) if a == 0: if b == 0 and c ==0: print("There are infinitely many solutions!") else: if b==0: print ("There is no solution") else: print("There is a unique solution x=%g" %(-1*c/b)) else: disc = b*b -4*a*c if disc > 0: x1 = (-b + sqrt(disc)) / 2 / a x2 = (-b - sqrt(disc)) / 2 / a if disc > 0: print("There are two distinct real roots x1=%g and x2=%g" % (x1, x2)) else: print("There are two conjugate roots x1=%g and x2=%g" % (x1, x2)) else: if disc == 0: print("There are two equal real roots x1=x2=%g" % (-1 * b / 2 / a)) else: x1 = (-b + sqrt(disc)) / 2 / a x2 = (-b - sqrt(disc)) / 2 / a print("There are two conjugate roots x1=%s and x2=%s" % (x1, x2))
123456789101112131415161718192021222324252627282930相关知识
使用 OpenCV 和 FER 在 Python 中进行实时情绪识别
php表达式ax 2 bx c=0,python求解ax² + bx + c = 0
python打印一定范围内的素数
宁波AX宠物医院发展战略研究
python运行run在哪
Python学习手册
设含有 m个方程的n元非齐次线性方程组为Ax=b且R(A)=r, 则( )
python 练习题
Python笔试题
python学习总结day2
网址: python解决ax^2+bx+c=0 https://m.mcbbbk.com/newsview348389.html
上一篇: 《宠物的秘密生活》电视剧全集在线 |
下一篇: 宠物记录1 |