nested if statement in python code