资源预览内容
第1页 / 共2页
第2页 / 共2页
亲,该文档总共2页全部预览完了,如果喜欢就下载吧!
资源描述
Python 次程Python 次程Python3 实例以下实例为通过户输数字,并计算次程:# -*- coding: UTF-8 -*-# Filename : test.py# author by : www.w3cschool.cn# 次程式 ax*2 + bx + c = 0# a、b、c 户提供# 导 cmath(复杂数学运算) 模块import cmatha = float(input(输 a: )b = float(input(输 b: )c = float(input(输 c: )# 计算d = (b*2) - (4*a*c)# 两种求解式sol1 = (-b-cmath.sqrt(d)/(2*a)sol2 = (-b+cmath.sqrt(d)/(2*a)print(结果为 0 和 1.format(sol1,sol2)执以上代码输出结果为:$ python test.py 输 a: 1输 b: 5输 c: 6结果为 (-3+0j) 和 (-2+0j)该实例中,我们使了 cmath (complex math) 模块的 sqrt() 法 来计算平根。 Python3 实例W3Cschool(www.w3cschool.cn)最的技术知识分享与学习平台此篇内容来于w3cschool.cn站户上传并发布。
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号