How to define nested while loops in Python?