Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2fca69e

Browse files
Create range_fn_float.py
1 parent 18899a4 commit 2fca69e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

‎range_fn_float.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Make a range function that works for `float` inputs
2+
3+
def float_for(start, stop, increment, stop_inclusive=True):
4+
if stop_inclusive:
5+
stop += increment
6+
7+
while start < stop:
8+
# The yield statement returns a `generator` object to
9+
# the one who calls the function which contains yield,
10+
# instead of simply returning a value.
11+
yield start
12+
start += increment
13+
14+
15+
for i in float_for(0.5, 0.95, 0.05):
16+
print(i)
17+
18+
"""
19+
Output:
20+
21+
0.5
22+
0.55
23+
0.6000000000000001
24+
0.6500000000000001
25+
0.7000000000000002
26+
0.7500000000000002
27+
0.8000000000000003
28+
0.8500000000000003
29+
0.9000000000000004
30+
0.9500000000000004
31+
"""

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /