import math


def logfactorial(n, k=0):
    """calculate the log of factorial n: log(1) + ... + log(n).
    optional argument: k (default 0) to calculate log(n!/k!)
    assumes n and k are non-negative integers.
    If k>n, the result is 0, not an error.
    Examples:

    >>> round(math.exp(logfactorial(5)),5)
    120.0
    >>> round(math.exp(logfactorial(5,4)),5)
    5.0
    >>> round(math.exp(logfactorial(5,5)),7)
    1.0
    >>> round(math.exp(logfactorial(10,8)),5)
    90.0
    """
    assert isinstance(n,int), "argument to logfactorial should be an integer"
    assert n >= 0, "argument n should be non-negative: " + str(n)
    assert type(k)==int, "optional argument k should be an integer"
    assert k >= 0, "optional argument k should be >= 0:" + str(k)
    res = 0
    for i in range(k+1,n+1):
        res += math.log(i)
    return res