docs

a slatepencil documentail site

View on GitHub

Define a procedure p2(x) that takes an integer parameter x. If x is greater than 1, the procedure returns the largest power of two that is less than x; otherwise, it returns 0. Use a loop.

def p2(x):
    base = 0
    while 2**base < x and 2**(base + 1) <= x:
        base += 1
    return base