So, we start with self.last_pos == 100
, so let’s figure out what values of random_x
get us out of the loop.
self.last_pos >= random_x - 100
isfalse
whenrandom_x >= 201
self.last_pos <= random_x + 100
isfalse
whenrandom_x < 0
Since random_x
can’t be less than 50
, it will never be less than 0
, so your while
loop will never exit.