- Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathrange_fn_float.py
31 lines (25 loc) · 619 Bytes
/
range_fn_float.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Make a range function that works for `float` inputs
deffloat_for(start, stop, increment, stop_inclusive=True):
ifstop_inclusive:
stop+=increment
whilestart<stop:
# The yield statement returns a `generator` object to
# the one who calls the function which contains yield,
# instead of simply returning a value.
yieldstart
start+=increment
foriinfloat_for(0.5, 0.95, 0.05):
print(i)
"""
Output:
0.5
0.55
0.6000000000000001
0.6500000000000001
0.7000000000000002
0.7500000000000002
0.8000000000000003
0.8500000000000003
0.9000000000000004
0.9500000000000004
"""