Bounce detection script in pyhton