How to exit a loop in Python The following code creates an infinite loop and I cannot understand why.