Python基于二分查找实现求整数平方根的方法
作者:charles_kao 时间:2023-01-17 01:33:49
本文实例讲述了Python基于二分查找实现求整数平方根的方法。分享给大家供大家参考,具体如下:
x=int(raw_input('please input a int:'))
if x<0:
retrun -1
low=0
high=x
ans=(low+high)/2.0
sign=ans
while ans**2 !=x:
if ans**2>x:
high=ans
else:
low=ans
ans=(low+high)/2.0
if sign==ans:
break
print ans
希望本文所述对大家Python程序设计有所帮助。
标签:Python,二分查找
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
rs.getrows的使用方法
2008-04-05 14:01:00
pytorch permute维度转换方法
2023-09-07 17:49:32
http协议详解(超详细)
2023-01-20 23:27:31
![](https://img.aspxhome.com/file/2023/7/117497_0s.jpg)
Python爬虫爬取Bilibili弹幕过程解析
2021-11-26 02:58:49
![](https://img.aspxhome.com/file/2023/5/95755_0s.png)
python实现ip代理池功能示例
2023-07-30 16:36:06
Python3查找列表中重复元素的个数的3种方法详解
2022-08-01 16:36:07
分享python机器学习中应用所产生的聚类数据集方法
2021-06-05 13:28:39
![](https://img.aspxhome.com/file/2023/7/97287_0s.jpg)
Mysql中复制详细解析
2024-01-13 20:46:25
python可视化之颜色映射详解
2021-01-27 01:23:52
![](https://img.aspxhome.com/file/2023/6/109326_0s.jpg)
多表关联同时更新多条不同的记录方法分享
2011-11-03 17:34:25
Javascript:keyCode键盘键码值表
2008-02-21 13:16:00
调用其他python脚本文件里面的类和方法过程解析
2021-01-11 13:27:14
Pytorch中实现CPU和GPU之间的切换的两种方法
2021-08-21 07:24:18
python自动化测试之破解滑动验证码
2023-12-01 09:36:25
![](https://img.aspxhome.com/file/2023/3/127913_0s.png)
linux环境下配置mysql5.6支持IPV6连接的方法
2024-01-20 01:56:13
![](https://img.aspxhome.com/file/2023/6/128356_0s.jpg)
python3+PyQt5实现自定义分数滑块部件
2023-08-03 02:15:28
![](https://img.aspxhome.com/file/2023/5/67255_0s.jpg)
Python缓存方案优化程序性能提高数据访问速度
2022-04-11 20:36:15
基于PHP读取csv文件内容的详解
2023-11-16 04:17:48
python循环输出三角形图案的例子
2022-05-16 08:38:37
![](https://img.aspxhome.com/file/2023/5/103265_0s.jpg)
TensorFlow实现简单线性回归
2023-09-18 13:23:45
![](https://img.aspxhome.com/file/2023/9/92519_0s.jpg)