[1.0, 1.7, 2.4, 3.1, 3.8, 4.5, 5.2, 5.9, 6.6, 7.3, 8.0]
编辑日期: 2024-11-28 文章阅读: 次
@author jackzhenguo
@desc
@date 2019/4/14
71 浮点数等差数列
def float_range(start, stop, n):
start,stop,n = float('%.2f' % start), float('%.2f' % stop),int('%.d' % n)
step = (stop-start)/n
lst = [start]
while n > 0:
start,n = start+step,n-1
lst.append(round((start), 2))
return lst
测试举例:
float_range(1, 8, 10)