生成一定范围内的浮点数,代码如下,请指正:
def flo(start, stop, step):
result = []
# 计算需要的次数
sum = int(abs((stop-start)/step+1))
#
for i in range(start, sum):
result.append(start)
start = start + step
result.append(stop)
return result
# call flo
b = flo(1, 3, 0.2)
运行结果为:
D:Python27python.exe C:/Users/Administrator/Desktop/PythonScripts/111.py
[1, 1.2, 1.4, 1.5999999999999999, 1.7999999999999998, 1.9999999999999998, 2.1999999999999997, 2.4, 2.6, 2.8000000000000003, 3]
Process finished with exit code 0
请各位大神指导一下,里边5个奇怪的数字怎么处理?
最后
以上就是酷炫豌豆最近收集整理的关于Python_生成浮点数的全部内容,更多相关Python_生成浮点数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复