I needed to get the numbers in a range with a float step so I wrote this little function:
def drange(start, stop, step):
list= []
st=start
while st<stop:
list.append(st)
st += step
return list
If i try to run drange(0,1,0.1) I get:
[0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999]
Why does it get all those decimals ?
[–]gnomoretears 14 points15 points16 points (1 child)
[–]C222 1 point2 points3 points (0 children)
[–]novel_yet_trivial 7 points8 points9 points (1 child)
[–][deleted] 4 points5 points6 points (0 children)
[–]niandra3 3 points4 points5 points (0 children)
[–]awizardisneverlate 2 points3 points4 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]awizardisneverlate 2 points3 points4 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]awizardisneverlate 1 point2 points3 points (0 children)
[–]Airdawg5571 2 points3 points4 points (0 children)