def outer(): def inner1(): if cond1: action1() if cond2: action2() def inner2(): for i in range(3): if cond3: action3() action4() return result