How to end a while loop in Python?