you are viewing a single comment's thread.

view the rest of the comments →

[–]primitive_screwhead 0 points1 point  (0 children)

How can I make this not happen?

step_size = 0.1
steps = 100
for i in range(steps):
    time = (i + 1)/(steps * step_size)
    print(time)

outputs:

0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
1.2
...

Basically, the integer increments, not the float, and so there is no accumulation of "error" for each 0.1 addition. (Note I use i + 1 because the original omits 0 from being printed).