Environment Diagrams: Difficult Solutions

writing out Environment Diagrams

For each function write out the environment diagram.

def higher_order(x):
    def inner(y):
        return x + y
    num = inner(x + 3)
    return num + inner(num)
higher_order(6)

def flip(digits):
    def slice(num):
        num, last = num // 10, num % 10
        return num, last
    flipped = 0
    while digits > 10:
        digits, last = slice(digits)
        flipped = flipped * 10 + last
    return flipped
flip(123456)