docs

a slatepencil documentail site

View on GitHub

Define a procedure multIAgen(m, n), which returns the product of m and n, both arguments are integers, but can be positive or negative. Don’t use *, but assume that multIA from the last problem is already defined for you. Your function should have type (int, int) -> int

def multIA(m, n):
    x = 0
    while (n > 0):
        n = n - 1
        x += m
    return x
def multIAgen(m, n):
    if ((m > 0 and n > 0) or (m < 0 and n < 0)):
        return multIA(abs(m), abs(n))
    else:
        return - multIA(abs(m), abs(n))