Convert While Loop Into For Loop In Python Using And In If Statement