Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 548 Bytes

71.md

File metadata and controls

29 lines (22 loc) · 548 Bytes
@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) 
# [1.0, 1.7, 2.4, 3.1, 3.8, 4.5, 5.2, 5.9, 6.6, 7.3, 8.0]
[上一个例子](70.md) [下一个例子](72.md)