File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ class float_range :
2
+ '''
3
+ Modified Python built-in function range that accepts floats as arguments.
4
+
5
+ Parameters
6
+ ----------
7
+ start : float (default: 0)
8
+ If "stop" is not given, interpreted as "stop" instead.
9
+ stop : float (default: 0)
10
+ step : float (default: 1)
11
+
12
+ Attributes
13
+ ----------
14
+ start
15
+ stop
16
+ step
17
+ current
18
+ '''
19
+ def __init__ (self , start = 0 , stop = 0 , step = 1 ):
20
+ if start and not stop :
21
+ stop , start = start , 0
22
+ self .start = start
23
+ self .current = start - step
24
+ self .stop = stop
25
+ self .step = step
26
+
27
+ def __iter__ (self ):
28
+ return self
29
+
30
+ def __next__ (self ):
31
+ self .current += self .step
32
+ if self .current < self .stop :
33
+ return self .current
34
+ raise StopIteration
You can’t perform that action at this time.
0 commit comments